# all values from a YAML dictionary like structure

**URL:** <https://forum.ansible.com/t/all-values-from-a-yaml-dictionary-like-structure/20843>\
**Category:** Ansible Project\
**Created:** [March 11, 2016, 3:52pm UTC](https://forum.ansible.com/t/all-values-from-a-yaml-dictionary-like-structure/20843 "2016-03-11T15:52:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Valerio\_Crini](https://avatars.discourse-cdn.com/v4/letter/v/7993a0/32.png) [@Valerio\_Crini](https://forum.ansible.com/u/Valerio_Crini)\
**Post date:** [March 11, 2016, 3:52pm UTC](https://forum.ansible.com/t/all-values-from-a-yaml-dictionary-like-structure/20843/1 "2016-03-11T15:52:30Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [March 11, 2016, 7:09pm UTC](https://forum.ansible.com/t/all-values-from-a-yaml-dictionary-like-structure/20843/2 "2016-03-11T19:09:34Z")

</div>

You can use the `map` filter, and the `join` filter.

“{{ node[‘test1’]|map(attribute=‘id’)|join(’ ') }}”

[http://jinja.pocoo.org/docs/dev/templates/](http://jinja.pocoo.org/docs/dev/templates/)

---

<div class="post-metadata">

**Author:** ![Valerio\_Crini](https://avatars.discourse-cdn.com/v4/letter/v/7993a0/32.png) [@Valerio\_Crini](https://forum.ansible.com/u/Valerio_Crini)\
**Post date:** [March 14, 2016, 12:04pm UTC](https://forum.ansible.com/t/all-values-from-a-yaml-dictionary-like-structure/20843/3 "2016-03-14T12:04:14Z")

</div>

Matt, you saved my day!

With your solution

“‘{{ node[‘test1’] | map(attribute=‘id’) | join(’' '‘) }}’”

I was able to do it,  
thanks a lot!
