Last active
July 10, 2018 06:08
-
-
Save halberom/bfac31287c0405a3df129d022a4ef318 to your computer and use it in GitHub Desktop.
ansible - example of using default var or result from nested dict
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": "a exists!" | |
} | |
PLAY [this should work, it doesn't] ******************************************************************************************************************************************************************************************************************************************** | |
TASK [debug] ******************************************************************************************************************************************************************************************************************************************************************* | |
ok: [localhost] => { | |
"msg": "" | |
} | |
PLAY [this works - but uses unoffically exposed 'vars'] ************************************************************************************************************************************************************************************************************************ | |
TASK [debug] ******************************************************************************************************************************************************************************************************************************************************************* | |
ok: [localhost] => { | |
"msg": "bcde exists!" | |
} | |
PLAY [this works] ************************************************************************************************************************************************************************************************************************************************************** | |
TASK [set_fact] **************************************************************************************************************************************************************************************************************************************************************** | |
ok: [localhost] | |
TASK [debug] ******************************************************************************************************************************************************************************************************************************************************************* | |
ok: [localhost] => { | |
"msg": "bcde exists!" | |
} | |
PLAY RECAP ********************************************************************************************************************************************************************************************************************************************************************* | |
localhost : ok=5 changed=0 unreachable=0 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
--- | |
- name: testing for a | |
hosts: localhost | |
gather_facts: False | |
connection: local | |
vars: | |
a: a exists! | |
tasks: | |
- debug: | |
msg: "{{ a|default(inventory_hostname|extract(hostvars, ['b', 'c', 'd', 'e'])) }}" | |
- name: testing for b: this should work, it doesn't | |
hosts: localhost | |
gather_facts: False | |
connection: local | |
vars: | |
b: | |
c: | |
d: | |
e: 'bcde exists!' | |
tasks: | |
- debug: | |
msg: "{{ a|default(inventory_hostname|extract(hostvars, ['b', 'c', 'd', 'e'])) }}" | |
- name: testing for b: this works - but uses unoffically exposed 'vars' | |
hosts: localhost | |
gather_facts: False | |
connection: local | |
vars: | |
b: | |
c: | |
d: | |
e: 'bcde exists!' | |
tasks: | |
- debug: | |
msg: "{{ a|default('b'|extract(vars, ['c', 'd', 'e'])) }}" | |
- name: testing for b: this works | |
hosts: localhost | |
gather_facts: False | |
connection: local | |
tasks: | |
- set_fact: | |
b: | |
c: | |
d: | |
e: 'bcde exists!' | |
- debug: | |
msg: "{{ a|default(inventory_hostname|extract(hostvars, ['b', 'c', 'd', 'e'])) }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment