Matt, you saved my day!
With your solution
"'{{ node['test1'] | map(attribute='id') | join('\' \'') }}'"
I was able to do it,
thanks a lot!
Il giorno venerdì 11 marzo 2016 20:17:17 UTC+1, Matt Martz ha scritto:
>
> You can use the `map` filter, and the `join` filter.
>
> "{{ node['test1']|map(attribute='id')|join(' ') }}"
>
> http://jinja.pocoo.org/docs/dev/templates/
>
> On Fri, Mar 11, 2016 at 9:52 AM, Valerio Crini <[email protected]
> <javascript:>> wrote:
>
>> Hi all,
>> I'd like to extract from a yaml complex dictionary as
>>
>> node:
>> host1:
>> - { id: '1' }
>> - { id: '2' }
>>
>> all values for 'id' for 'host1'
>>
>> in order to convert this snipped of code from
>>
>> id_list: {{ xxx }}
>>
>> in
>>
>> id_list: '1' '2'
>>
>> in python I can do the following
>>
>>
>> >>> node= {'test1':[{'id':'1'},{'id':'2'}]}
>> >>> node
>> {'test1': [{'id': '1'}, {'id': '2'}]}
>> >>> " ".join(["'%s'"% x['id'] for x in node['test1']]) #this is xxx
>> "'1' '2'"
>>
>> but in ansible how can obtain the same?
>>
>> --
>> 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/028602aa-642d-4157-b096-f6b384e32126%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/ansible-project/028602aa-642d-4157-b096-f6b384e32126%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/2e97e8d9-27b3-4487-9ee3-ad962e3f1bc3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.