November 2017
Intermediate to advanced
266 pages
5h 34m
English
There are times when we want to execute certain tasks based upon the conditions. when statement is used to determine those conditions and execute the specified task if the condition evaluates to true. Let us take an example to execute the uptime command, if we pass the parameter clock to the variable clock:
- hosts: myrouters tasks: - shell: uptime - debug: msg: "This is clock condition" when: clock == "clock" - debug: msg: "This is NOT a clock condition" when: clock != "clock"
Execution from command line: With and incorrect value clock123 being passed to clock variable):
ansible-playbook checkif.yml --extra-vars "clock=clock123"
The output of the execution with incorrect values provided:
As we see in preceding output, ...
Read now
Unlock full access