I have a static dictionary which I need to combine (to add it) to dynamic dictionary.
"static": [
{
"item1": "abc",
"item2": "def",
"item3": "dkslks",
"item4": "kkk"
}
]
"dynamic": [
{
"item5": "aa",
"item6": "aaa",
"item7: "aaaa"
},
{
"item5": "bb",
"item6": "bbb",
"item7: "bbbb"
},
{
"item5": "cc",
"item6": "ccc",
"item7: "cccc"
}
]
I need to get the following result:
"combined": [
{
"item1": "abc",
"item2": "def",
"item3": "dkslks",
"item4": "kkk"
"item5": "aa",
"item6": "aaa",
"item7: "aaaa"
},
{
"item1": "abc",
"item2": "def",
"item3": "dkslks",
"item4": "kkk"
"item5": "bb",
"item6": "bbb",
"item7: "bbbb"
},
{
"item1": "abc",
"item2": "def",
"item3": "dkslks",
"item4": "kkk"
"item5": "cc",
"item6": "ccc",
"item7: "cccc"
}
]
I managed to combine it but just for the first part of this dict, not for all the members. Result was like this:
- set_fact:
combined: "{{ static|combine(dynamic) }}"
"combined": [
{
"item1": "abc",
"item2": "def",
"item3": "dkslks",
"item4": "kkk"
"item5": "aa",
"item6": "aaa",
"item7: "aaaa"
}
]
So I need to put it in a loop, but cannot find the right way. Here is some things I tried:
- set_fact:
combined: "{{ static | combine(json_query('[*]') | dynamic) }}"
or similar variations like this one
- set_fact:
combined: "{{ static | combine(dynamic) | json_query('[*]') }}"
or
- set_fact:
combined: "{{ dynamic | combine(static) }}"
loop: "{{dynamic | json_query('[*]')}}"
Would someone be kind to help?
Thanks!