From the course: Ansible for Automation Essential Training: Advanced Playbooks, Roles, and Diverse Hosts
Unlock this course with a free trial
Join today to access over 24,900 courses taught by industry experts.
Adding conditionals - Ansible Tutorial
From the course: Ansible for Automation Essential Training: Advanced Playbooks, Roles, and Diverse Hosts
Adding conditionals
- [Instructor] Conditionals are another feature I couldn't live without as they make frequent appearances in my playbooks. In essence, they are simple or compound IF statements. They're evaluated for each host being operated against, and if the condition isn't found to be true, the host is skipped for this task. The Win Task Level Parameter is used to designate a conditional. After that comes the condition in the form of value 1 compared in some way to value 2. As in when x > 2. As shown, you can use standard mathematical operators like >, <, =, and !=. You can also do the written out version of these with no spaces in the words as in greaterthan, lessthan, or equalto. I've duplicated the previous loop playbook and named it conditionals.yml. I'm going to add a membership conditional which checks if a value exists in a list. I'll change my tasks so that it will only add users that aren't designated to be ignored. Up in the vars section, I'll add a variable. And I'll name it…
Contents
-
-
-
(Locked)
Installing collections2m 20s
-
Construct a simple playbook4m 19s
-
(Locked)
Using variables5m 7s
-
(Locked)
Using loops2m 45s
-
(Locked)
Adding conditionals4m 57s
-
(Locked)
Utilizing blocks3m 49s
-
(Locked)
Exploring templates4m 29s
-
(Locked)
Discovering handlers2m 23s
-
(Locked)
Using tags2m 53s
-
(Locked)
Testing plays with check mode2m 15s
-
(Locked)
Conditional failure with assert2m 20s
-
(Locked)
Failure and change control2m 32s
-
(Locked)
Nesting loops3m 29s
-
(Locked)
Creating dynamic inventory files3m 7s
-
(Locked)
Challenge: Create a complex playbook1m 17s
-
Solution: Verify the complex playbook2m 52s
-
(Locked)
-
-
-
-