Ansible conditionals using When & Register

Published: 13 May 2021
on channel: LondonIAC / Dennis McCarthy / Automation Engineer
2,869
39

I'll show you how to use some basic but powerful conditional statements to control when a task runs in this demo.

This is what's covered:

• I’ll be using 2 servers today. 1 centos 8 and one ubuntu 20.04
• I’ll use the fact: "ansible_os_family" to only create a file on a Debian based server
• Next we’ll run a command to get the AWS Instance type of each node.
• If the server is a T2.small, we’ll create a file, otherwise, ignore it.
• To do this we’ll use "register" to collect the output of the command
• Then use “when:” to only run the task if it’s a T2.small.
• Finally we’ll reverse the conditional

Once you understand conditionals, adapt my examples on your own code and see how much of a difference it gives you.

As always, Subscribe for more videos like this and please message me in the comments if you'd like me to make a demo on something you'd like to see.


Watch video Ansible conditionals using When & Register online without registration, duration hours minute second in high quality. This video was added by user LondonIAC / Dennis McCarthy / Automation Engineer 13 May 2021, don't forget to share it with your friends and acquaintances, it has been viewed on our site 2,869 once and liked it 39 people.