I'd like to merge a simple list / array into a nested dictionary (correct me if one of those terms is wrong)
Playbook
---
- hosts: localhost
gather_facts: no
vars:
- simple:
- right
- middle
- top
- nested:
- hostname: foo
path:
- left
- hostname: bar
path:
- blue
- green
- yellow
- "{{ simple }}"
tasks:
- name: content of nested
debug:
msg: "{{ nested }}"
The actual output is:
PLAY [localhost] ***************************************************************
TASK [content of nested] *******************************************************
Wednesday 31 August 2016 08:55:13 +0200 (0:00:00.025) 0:00:00.025 ******
ok: [localhost] => {
"msg": [
{
"hostname": "foo",
"path": [
"left"
]
},
{
"hostname": "bar",
"path": [
"blue",
"green",
"yellow",
[
"right",
"middle",
"top"
]
]
}
]
}
PLAY RECAP *********************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=0
What I'd like to have is (output manipulated)
PLAY [localhost] ***************************************************************
TASK [content of nested] *******************************************************
Wednesday 31 August 2016 08:55:13 +0200 (0:00:00.025) 0:00:00.025 ******
ok: [localhost] => {
"msg": [
{
"hostname": "foo",
"path": [
"left"
]
},
{
"hostname": "bar",
"path": [
"blue",
"green",
"yellow",
"right",
"middle",
"top"
]
}
]
}
PLAY RECAP *********************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=0
Thank you for your ideas!
Best Answer
The simplest thing in this example would probably be (I'm not sure about the idea behind defining variables this way):