-
-
Save rgodishela/f6252fe0d6611475cbc335707ef73461 to your computer and use it in GitHub Desktop.
ansible - example of setting a complex var with set_fact
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 [foo] ******************************************************************** | |
GATHERING FACTS *************************************************************** | |
ok: [localhost] | |
TASK: [set_fact ] ************************************************************* | |
ok: [localhost] | |
TASK: [debug ] **************************************************************** | |
ok: [localhost] => { | |
"var": { | |
"complex_arg": [ | |
{ | |
"address": "mars", | |
"name": "bob" | |
}, | |
{ | |
"name": "mary" | |
} | |
] | |
} | |
} |
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: foo | |
tasks: | |
- set_fact: | |
complex_arg: | |
- name: bob | |
address: mars | |
- name: mary | |
- debug: | |
var: complex_arg |
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: foo | |
tasks: | |
# or with a json value | |
- set_fact: | |
complex_arg: '[{"name":"bob", "address":"mars"},{"name":"mary"}]' | |
- debug: | |
var: complex_arg |
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: foo | |
vars: | |
complex_arg: '[{"name":"bob", "address":"mars"},{"name":"mary"}]' | |
tasks: | |
- set_fact: complex_arg | |
- debug: | |
var: complex_arg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment