I need to conditionally transform a list of objects defined in a JSON file. The problem with the playbook is that I need the transformation to yield either the value of docker.network
or id
. Simply put, I need to figure out some kind of ternary operator for transforming lists. The playbook results in:
"msg": "['baz', AnsibleUndefined]"
I need
"msg": "['baz', 'bar']"
Playbook:
vars:
daemons: "{{ lookup('file','./test.json') | from_json }}"
tasks:
- name: Transform
debug:
msg: "{{ daemons | map(attribute='docker.network') }}"
test.json:
[
{
"id": "foo",
"docker": {
"network": "baz"
}
},
{
"id": "bar",
"docker": {
}
}
]