Slide 27
Slide 27 text
Conditionals
tasks:
- name: "shutdown Debian systems"
command: /sbin/shutdown -t now
when: ansible_os_family == “Debian” #use Jinja2 expressions
tasks:
- command: /bin/false
register: result
ignore_errors: True
- command: /bin/something
when: result|failed #use Jinja2 filter
- command: /bin/something_else
when: result|success
- command: /bin/still/something_else
when: result|skipped
tasks:
- command: echo {{ item }}
with_items: [ 0, 2, 4, 6, 8, 10 ]
when: item > 5
Condition in Roles: this works by applying the conditional to every task in the role. Roles that
not match condition are skipped.
- hosts: webservers
roles:
- { role: some_role, when: ansible_os_family == 'Debian' }