Skip to content

Instantly share code, notes, and snippets.

@rgodishela
Forked from halberom/output
Created May 22, 2017 04:57
Show Gist options
  • Save rgodishela/f6252fe0d6611475cbc335707ef73461 to your computer and use it in GitHub Desktop.
Save rgodishela/f6252fe0d6611475cbc335707ef73461 to your computer and use it in GitHub Desktop.
ansible - example of setting a complex var with set_fact
PLAY [foo] ********************************************************************
GATHERING FACTS ***************************************************************
ok: [localhost]
TASK: [set_fact ] *************************************************************
ok: [localhost]
TASK: [debug ] ****************************************************************
ok: [localhost] => {
"var": {
"complex_arg": [
{
"address": "mars",
"name": "bob"
},
{
"name": "mary"
}
]
}
}
---
- hosts: foo
tasks:
- set_fact:
complex_arg:
- name: bob
address: mars
- name: mary
- debug:
var: complex_arg
---
- hosts: foo
tasks:
# or with a json value
- set_fact:
complex_arg: '[{"name":"bob", "address":"mars"},{"name":"mary"}]'
- debug:
var: complex_arg
---
- 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