I have the following structure:
“a”: {
“v1”: 1,
“v2”: “A”
}
“b”: {
“v1”: 2,
“v2”: “B”
}
It is read from an external json source using:
- set_fact: envs="{{ external.stdout | from_json }}"
I can loop/iterate over it only by using with_dict:
- debug: msg="Item is {{ item.key }} with value {{ item.value.v1}} and{{ item.value.v2}}" with_dict: envs
but if I try anything else it throws exception:
AttributeError: ‘unicode’ object has no attribute ‘items’
I tried the following:
- set_fact: envs_list="{{ envs | dictsort }}"
and:
- debug: var=item with_items: envs.items()
and inside template:
{% for env in envs|dictsort %}
and:
{% for env, setting in envs.`iteritems`() %}
…with the same result.
I would need to use that structure inside a template…
I’m using ansible 1.9.1 on CentOS 6
Any idea how to solve that?