Last active
August 29, 2015 14:07
-
-
Save manicminer/e95580cc5e30ec616daf to your computer and use it in GitHub Desktop.
Conditional fail
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: localhost | |
connection: local | |
tasks: | |
- set_fact: | |
is_test: "{{ env == 'development' or 'test' in env }}" | |
- set_fact: | |
security_group: blah | |
when: is_test | |
- set_fact: | |
security_group: blurh | |
when: not is_test | |
- debug: msg="is_test={{ is_test }}" | |
- debug: msg="security_group={{ security_group }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[root@localhost ansible]# ansible-playbook -i 'localhost,' test.yml -e 'env=prod' | |
PLAY [localhost] ************************************************************** | |
GATHERING FACTS *************************************************************** | |
ok: [localhost] | |
TASK: [set_fact ] ************************************************************* | |
ok: [localhost] | |
TASK: [set_fact ] ************************************************************* | |
skipping: [localhost] | |
TASK: [set_fact ] ************************************************************* | |
skipping: [localhost] | |
TASK: [debug msg="is_test={{ is_test }}"] ************************************* | |
ok: [localhost] => { | |
"msg": "is_test=False" | |
} | |
TASK: [debug msg="security_group={{ security_group }}"] *********************** | |
fatal: [localhost] => One or more undefined variables: 'security_group' is undefined | |
FATAL: all hosts have already failed -- aborting | |
PLAY RECAP ******************************************************************** | |
to retry, use: --limit @/root/test.retry | |
localhost : ok=3 changed=0 unreachable=1 failed=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[root@localhost ansible]# ansible-playbook -i 'localhost,' test.yml -e 'env=test' | |
PLAY [localhost] ************************************************************** | |
GATHERING FACTS *************************************************************** | |
ok: [localhost] | |
TASK: [set_fact ] ************************************************************* | |
ok: [localhost] | |
TASK: [set_fact ] ************************************************************* | |
ok: [localhost] | |
TASK: [set_fact ] ************************************************************* | |
skipping: [localhost] | |
TASK: [debug msg="is_test={{ is_test }}"] ************************************* | |
ok: [localhost] => { | |
"msg": "is_test=True" | |
} | |
TASK: [debug msg="security_group={{ security_group }}"] *********************** | |
ok: [localhost] => { | |
"msg": "security_group=blah" | |
} | |
PLAY RECAP ******************************************************************** | |
localhost : ok=5 changed=0 unreachable=0 failed=0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment