Ansible: set facts using conditionals

Published: 13 December 2021
on channel: LondonIAC / Dennis McCarthy / Automation Engineer
4,676
80

Ansible – Set_facts contional example

Checkout all the code on my gist: https://gist.github.com/dmccuk/63d8f6...

In ansible, like any other programming language, at some point, we’ll want to set a variable for something. This is fairly simple to do when it’s just one value, but if we need to pick that value from the server we run ansible against, it gets a bit trickier.

For example:

I’m running my playbook/role against a list of servers. I need to be able to identify which DC each server is in so I can apply the correct nameservers, timeservers, nfs mounts points, and anything else. I want my code to run on all the servers, set the fact based on something unique to that server, and then apply the configuration.

In this video I’ll show you the following:

• How to generate static facts
• How to use a conditional statement to set a fact
• How to combine the facts into a string


Watch video Ansible: set facts using conditionals online without registration, duration hours minute second in high quality. This video was added by user LondonIAC / Dennis McCarthy / Automation Engineer 13 December 2021, don't forget to share it with your friends and acquaintances, it has been viewed on our site 4,676 once and liked it 80 people.