Created
June 12, 2019 08:18
-
-
Save halberom/237d38958e64d7513e83df0962d1fb4e to your computer and use it in GitHub Desktop.
ansible - example of using default() with different var states
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 | |
gather_facts: false | |
vars: | |
foo: '' | |
bar: foo | |
#abc | |
xyz: true | |
tasks: | |
- debug: | |
msg: "{{ foo|default(false) }}" | |
- debug: | |
msg: "{{ foo|default(false, true) }}" | |
- debug: | |
msg: "{{ bar|default(false) }}" | |
- debug: | |
msg: "{{ bar|default(false, true) }}" | |
- debug: | |
msg: "{{ abc|default(false) }}" | |
- debug: | |
msg: "{{ abc|default(false, true) }}" | |
- debug: | |
msg: "{{ xyz|default(false) }}" | |
- debug: | |
msg: "{{ xyz|default(false, true) }}" |
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
PLAY [localhost] ********************************************************************************************************************************************************************* | |
TASK [debug] ************************************************************************************************************************************************************************* | |
ok: [localhost] => { | |
"msg": "" | |
} | |
TASK [debug] ************************************************************************************************************************************************************************* | |
ok: [localhost] => { | |
"msg": false | |
} | |
TASK [debug] ************************************************************************************************************************************************************************* | |
ok: [localhost] => { | |
"msg": "foo" | |
} | |
TASK [debug] ************************************************************************************************************************************************************************* | |
ok: [localhost] => { | |
"msg": "foo" | |
} | |
TASK [debug] ************************************************************************************************************************************************************************* | |
ok: [localhost] => { | |
"msg": false | |
} | |
TASK [debug] ************************************************************************************************************************************************************************* | |
ok: [localhost] => { | |
"msg": false | |
} | |
TASK [debug] ************************************************************************************************************************************************************************* | |
ok: [localhost] => { | |
"msg": true | |
} | |
TASK [debug] ************************************************************************************************************************************************************************* | |
ok: [localhost] => { | |
"msg": true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment