# How do i loop over include\_vars objects under a dictionary ?

**URL:** <https://forum.ansible.com/t/how-do-i-loop-over-include-vars-objects-under-a-dictionary/32361>\
**Category:** Ansible Project\
**Created:** [March 2, 2020, 5:37am UTC](https://forum.ansible.com/t/how-do-i-loop-over-include-vars-objects-under-a-dictionary/32361 "2020-03-02T05:37:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shifa\_Shaikh](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Shifa\_Shaikh](https://forum.ansible.com/u/Shifa_Shaikh)\
**Post date:** [March 2, 2020, 5:37am UTC](https://forum.ansible.com/t/how-do-i-loop-over-include-vars-objects-under-a-dictionary/32361/1 "2020-03-02T05:37:42Z")

</div>

I have a include\_vars file with the below entries in listings.yml

`

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [March 2, 2020, 6:10am UTC](https://forum.ansible.com/t/how-do-i-loop-over-include-vars-objects-under-a-dictionary/32361/2 "2020-03-02T06:10:17Z")

</div>

The variables from the file are assigned into the dictionary "user1". Fix the  
variables' references

&nbsp;&nbsp;&nbsp;&nbsp;- debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg: "Name {{ user1[item].0.name }} on path {{ user1[item].0.path }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loop:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- "{{ inventory\_hostname }}"

With single item the loop is not necessary

&nbsp;&nbsp;&nbsp;&nbsp;- debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg: "Name {{ user1[inventory\_hostname].0.name }} on  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;path {{ user1[inventory\_hostname].0.path }}"

HTH,  
&nbsp;&nbsp;-vlado

---

<div class="post-metadata">

**Author:** ![Shifa\_Shaikh](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@Shifa\_Shaikh](https://forum.ansible.com/u/Shifa_Shaikh)\
**Post date:** [March 2, 2020, 6:17am UTC](https://forum.ansible.com/t/how-do-i-loop-over-include-vars-objects-under-a-dictionary/32361/3 "2020-03-02T06:17:02Z")

</div>

@Vladimir this prints only the first name and path under the hostname.

I wish to loop all name and path under the given host.

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [March 2, 2020, 6:23am UTC](https://forum.ansible.com/t/how-do-i-loop-over-include-vars-objects-under-a-dictionary/32361/4 "2020-03-02T06:23:47Z")

</div>

Try this

&nbsp;&nbsp;&nbsp;&nbsp;- debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg: "Name {{ item.name }} on path {{ item.path }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loop: "{{ user1[inventory\_hostname] }}"

HTH,

&nbsp;&nbsp;-vlado
