# Access all the sub-elements in a yaml map

**URL:** <https://forum.ansible.com/t/access-all-the-sub-elements-in-a-yaml-map/18415>\
**Category:** Ansible Project\
**Created:** [June 5, 2015, 6:02am UTC](https://forum.ansible.com/t/access-all-the-sub-elements-in-a-yaml-map/18415 "2015-06-05T06:02:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Naween\_Ghimire](https://avatars.discourse-cdn.com/v4/letter/n/e0b2c6/32.png) [@Naween\_Ghimire](https://forum.ansible.com/u/Naween_Ghimire)\
**Post date:** [June 5, 2015, 6:02am UTC](https://forum.ansible.com/t/access-all-the-sub-elements-in-a-yaml-map/18415/1 "2015-06-05T06:02:17Z")

</div>

Hi I have been trying to access all the sub-elements available in a map but i am unable to do so:

Here’s my usecase:

A yaml map is defined as follows:

object:  
element1: “value1”  
element2: “value2”  
element3: “value3”

…  
…  
…  
elementn: “valuen”

In a task i need to access all the values (value1,value2,value3,…,valuen)

I tried the following:

- name: pass values to script  
debug: “msg={{ item }}”  
with\_items:
- “{{ object }}”

But this doesn’t seem to work.

Whereas the following works,

- name: pass values to script  
debug: “msg={{ item }}”  
with\_items:

- “{{ object.element1 }}”

- “{{ object.element2 }}”

But this is not scalable, and i have a usecase where the number of elements might vary. Is there a way to get this done in ansible ?

Regards,  
Naween

---

<div class="post-metadata">

**Author:** ![benno\_joy](https://avatars.discourse-cdn.com/v4/letter/b/73ab20/32.png) [@benno\_joy](https://forum.ansible.com/u/benno_joy)\
**Post date:** [June 5, 2015, 6:10am UTC](https://forum.ansible.com/t/access-all-the-sub-elements-in-a-yaml-map/18415/2 "2015-06-05T06:10:58Z")

</div>

i think what you need is with\_dict: object and use it via item.key and item.value

---

<div class="post-metadata">

**Author:** ![Naween\_Ghimire](https://avatars.discourse-cdn.com/v4/letter/n/e0b2c6/32.png) [@Naween\_Ghimire](https://forum.ansible.com/u/Naween_Ghimire)\
**Post date:** [June 5, 2015, 6:42am UTC](https://forum.ansible.com/t/access-all-the-sub-elements-in-a-yaml-map/18415/3 "2015-06-05T06:42:26Z")

</div>

Thanks. Works as expected.
