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.
---
- hosts: all
gather_facts: False
vars:
a:
first:
second: 'foo'
b:
first:
third: 'bar'
tasks:
- set_fact: c="{{ a | combine(b) }}"
- debug: var=c
- debug: msg="{% print a.__class__ %}"
- debug: msg="{% print b.__class__ %}"
- debug: msg="{% print c.__class__ %}"...
Which when run produces:
PLAY [all]
********************************************************************
TASK: [set_fact c="{{ a | combine(b) }}"]
*************************************
ok: [localhost]
TASK: [debug var=c]
***********************************************************
ok: [localhost] => {
"var": {
"c": {
"first": {
"second": "foo",
"third": "bar"
}
}
}
}
TASK: [debug msg="<class 'jinja2.runtime.StrictUndefined'>"]
******************
ok: [localhost] => {
"msg": "<type 'dict'>"
}
TASK: [debug msg="<class 'jinja2.runtime.StrictUndefined'>"]
******************
ok: [localhost] => {
"msg": "<type 'dict'>"
}
TASK: [debug msg="<class 'jinja2.runtime.StrictUndefined'>"]
******************
ok: [localhost] => {
"msg": "<type 'unicode'>"
}
PLAY RECAP
********************************************************************
localhost : ok=5 changed=0 unreachable=0 failed=0
Notice that both parent dicts are of type dict, but the merged child is of
type unicode? Any help much appreciated. :)
-Cheers Max.
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/c393c455-724e-4ae2-8ac2-7321d73172e2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.