At the moment Ansible prefers yes/no for module booleans, however booleans in playbooks are still using True/False, rather than yes/no. This changes modifies boolean uses in playbooks (and man pages) to favor yes/no rather than True/False. This change includes: - Adaptation of documentation and examples to favor yes/no - Modification to manpage output to favor yes/no (the docsite output already favors yes/no)
28 lines
1.1 KiB
YAML
28 lines
1.1 KiB
YAML
# here's a cool advanced topic about how to perform conditional logic in ansible without resorting
|
|
# to writing your own module that defines facts. You can do that too, and it's easy to do, but
|
|
# often you just want to run a command and then decide whether to run some steps or not. That's
|
|
# easy to do, and here we'll show you how.
|
|
|
|
- name: test playbook
|
|
user: root
|
|
hosts: all
|
|
|
|
tasks:
|
|
|
|
# it is possible to save the result of any command in a named register. This variable will be made
|
|
# available to tasks and templates made further down in the execution flow.
|
|
|
|
- action: shell grep hi /etc/motd
|
|
ignore_errors: yes
|
|
register: motd_result
|
|
|
|
# and here we access the register. Note that variable is structured data because
|
|
# it is a return from the command module. The shell module makes available variables such as
|
|
# as 'stdout', 'stderr', and 'rc'.
|
|
|
|
# here we run the next action only if the previous grep returned true
|
|
|
|
- action: shell echo "motd contains the word hi"
|
|
only_if: "${motd_result.rc} == 0"
|
|
|
|
|