I got this simple playbook where I am trying to construct a dictionary from a list of key/value pairs using the combine
filter. The problem is that it does not seem to work when looping over the pairs (I've tried loop, with_dict, with_items).
- name: test jinja2 combine filter
hosts: localhost
- name: test combine
vars:
x: {'three', 3}
set_fact:
x: "{{ x | combine(item) }}"
with_items: [{'one': 1},{'two': 2}]
# I am expecting to see the two new dicts here,
# but only the last one in the list is added
- name: print x
debug: msg={{ x }}
Expected output:
ok: [localhost] => {
"msg": {
"three": 3,
"one": 1,
"two": 2
}
}
My result:
ok: [localhost] => {
"msg": {
"three": 3,
"two": 2
}
}
From this post, it seems that there's no out of the box solution for this kind of problem. While it wouldn't be hard to write a custom plugin, I am still wondering if there is a standard solution without writing a plugin.