Thanks, this works!
But in that case I need to put that expression everywhere I want to use
that variable.
Is there a way to register new object variable while running the playbook?
2015. november 4., szerda 17:34:59 UTC+1 időpontban Matt Martz a következőt
írta:
>
> Use `from_json` during the "last mile", as the set_fact is casting that
> output back to a string.
>
> Such as:
>
> {% for env in envs|from_json|dictsort %}
>
>
> and drop `from_json` from your set_fact. Or just use
> `external.stdout|from_json|dictsort` where you need it, and don't use
> set_fact.
>
> On Wed, Nov 4, 2015 at 10:03 AM, Bence Takács <[email protected]
> <javascript:>> wrote:
>
>> UPDATE: Python 2.6.6
>>
>>
>> 2015. november 4., szerda 16:46:27 UTC+1 időpontban Bence Takács a
>> következőt írta:
>>>
>>> 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?
>>>
>> --
>> 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] <javascript:>.
>> To post to this group, send email to [email protected]
>> <javascript:>.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ansible-project/4dd854c0-f9e9-4ec1-80f1-6ad4548151f4%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/ansible-project/4dd854c0-f9e9-4ec1-80f1-6ad4548151f4%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> Matt Martz
> @sivel
> sivel.net
>
--
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/0189e281-f15c-4333-9d37-40df14ef8d2e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.