2012-03-21 00:55:24 +01:00
|
|
|
---
|
2012-10-27 23:55:35 +02:00
|
|
|
# this is a demo of conditional executions using 'when' statements, which can skip
|
|
|
|
# certain tasks on machines/platforms/etc where they do not apply.
|
2012-03-21 00:55:24 +01:00
|
|
|
|
|
|
|
- hosts: all
|
|
|
|
user: root
|
|
|
|
|
|
|
|
vars:
|
|
|
|
favcolor: "red"
|
2012-10-27 23:55:35 +02:00
|
|
|
dog: "fido"
|
|
|
|
cat: "whiskers"
|
2012-03-21 00:55:24 +01:00
|
|
|
ssn: 8675309
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
|
2012-10-27 23:55:35 +02:00
|
|
|
- name: "do this if my favcolor is blue, and my dog is named fido"
|
2012-03-21 00:55:24 +01:00
|
|
|
action: shell /bin/false
|
2013-05-05 19:30:26 +02:00
|
|
|
when: favcolor == 'blue' and dog == 'fido'
|
2012-10-27 23:55:35 +02:00
|
|
|
|
|
|
|
- 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'
|
2012-10-27 23:55:35 +02:00
|
|
|
|
|
|
|
- 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
|
|
|
|
2012-10-27 23:55:35 +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 ]
|
2012-10-27 23:55:35 +02:00
|
|
|
|
|
|
|
- name: "do this if a variable named hippo is NOT defined"
|
2012-03-22 01:00:48 +01:00
|
|
|
action: shell /bin/true
|
2013-05-05 19:30:26 +02:00
|
|
|
when: hippo is not defined
|
2012-10-27 23:55:35 +02:00
|
|
|
|
|
|
|
- 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
|
2012-10-27 23:55:35 +02:00
|
|
|
|
2012-03-21 00:55:24 +01:00
|
|
|
|