1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/examples/playbooks/conditionals_part2.yml

41 lines
1.1 KiB
YAML
Raw Normal View History

---
# this is a demo of conditional executions using 'when' statements, which can skip
# certain tasks on machines/platforms/etc where they do not apply.
- hosts: all
user: root
vars:
favcolor: "red"
dog: "fido"
cat: "whiskers"
ssn: 8675309
tasks:
- name: "do this if my favcolor is blue, and my dog is named fido"
action: shell /bin/false
2013-05-05 19:30:26 +02:00
when: favcolor == 'blue' and dog == 'fido'
- name: "do this if my favcolor is not blue, and my dog is named fido"
action: shell /bin/true
2013-05-05 19:30:26 +02:00
when: favcolor != 'blue' and dog == 'fido'
- name: "do this if my SSN is over 9000"
action: shell /bin/true
2013-05-05 19:30:26 +02:00
when: ssn > 9000
2012-08-07 02:00:31 +02:00
- name: "do this if I have one of these SSNs"
action: shell /bin/true
2013-05-05 19:30:26 +02:00
when: ssn in [ 8675309, 8675310, 8675311 ]
- name: "do this if a variable named hippo is NOT defined"
action: shell /bin/true
2013-05-05 19:30:26 +02:00
when: hippo is not defined
- name: "do this if a variable named hippo is defined"
action: shell /bin/true
2013-05-05 19:30:26 +02:00
when: hippo is defined