October 2017
Intermediate to advanced
326 pages
7h 20m
English
In Ansible, it is possible to use flow control statements such as loops or conditionals using variables as input. This can be used to repeat tasks on a certain dataset and avoid executing some tasks if a few conditions are not met: we might want to use different commands depending on the underlying system of our server.
We have already seen an example of conditionals using the when clause in our previous examples, but let's explain it a bit more:
---- hosts: all user: root tasks: - command: /bin/false register: result ignore_errors: True - debug: msg="fail!" when: result|failed - debug: msg="success!" when: result|succeeded
The preceding code is very easy to read: a command is executed (ignoring the potential errors so our playbook ...
Read now
Unlock full access