Ansible: set facts using conditionals
ฝัง
- เผยแพร่เมื่อ 8 ม.ค. 2025
- Ansible - Set_facts contional example
Checkout all the code on my gist: gist.github.co...
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
Great concise explanation. Thanks
Good stuff Dennis, good explanation.
Thanks Ken.
Nice explanation
thanks, I'm glad it was helpful!
Why not use vars instead of set_facts?
Very nice video. Thanks
Thanks. I'm glad you like it and I hope it was useful.
Very useful - thank you.
Glad it was helpful!
Why assert conditions are not printing anything
Hi Raj, I don't use "assert" in this demo. Do you mean one of my other videos?
Nice video, thanks
Glad you liked it!