Problem with function to merge nested dictionaries

Hi All,

I’m using ansible 1.9.3, and want to merge two nested dicts to template to a config file. I’ve written a combine function similar to whats in 2.n.n. The problem is that the merged dictionary appears to be unicode preventing me from iterating over it in the template. This is the combine function:

`
def combine(original, update):
for key, value in original.items():
if not key in update:
update[key] = value
elif isinstance(value, dict):
combine(value, update[key])

return update

class FilterModule(object):

def filters(self):
return {
‘combine’: combine,
}
`

My testcase is this.

`

So this is the solution.

`

  • set_fact:
    c: “{{ a | combine(b) }}”
    `

https://github.com/ansible/ansible/issues/5463

set fact typecasts everything as a string when using key=value syntax. Use yaml syntax and you’re good to go.

Many many thanks to an off list unsung hero…

-Max.