# printing the items on dictionary format

**URL:** <https://forum.ansible.com/t/printing-the-items-on-dictionary-format/37762>\
**Category:** Ansible Project\
**Created:** [March 14, 2023, 12:58pm UTC](https://forum.ansible.com/t/printing-the-items-on-dictionary-format/37762 "2023-03-14T12:58:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Veera](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/veera/32/4107_2.png) [@Veera](https://forum.ansible.com/u/Veera)\
**Post date:** [March 14, 2023, 12:58pm UTC](https://forum.ansible.com/t/printing-the-items-on-dictionary-format/37762/1 "2023-03-14T12:58:27Z")

</div>

I have the items defined in the file vars/myvars.yml as below:

_world:_  
_asia:_  
_country: india_  
_state: maha_  
_city: mumbai_

_n\_america:_  
_nation: canada_  
_province : quebec_  
_city: montreal_

When I try to print them with a loop and subelements , i am missing something  
_- name: play to print the details_  
_hosts: localhost_  
_gather\_facts: no_  
_vars:_  
_- vars/myvars.yml_  
_tasks:_  
_- name: printing the details of montreal_  
_debug:_  
_msg: “{{ item[2] [‘city’]}}”_  
_loop: “{{ world | subelements(‘n\_america’) | dict2items }}”_

I receive a error like “obj must be a list of dicts or a nested dict”}

msg: with "\*world .\*_n\_america.city" will work_  
I want to print this through loop only , as i need to process other items also.

Thanks ,

---

<div class="post-metadata">

**Author:** ![Avinash\_Jadhav](https://avatars.discourse-cdn.com/v4/letter/a/958977/32.png) [@Avinash\_Jadhav](https://forum.ansible.com/u/Avinash_Jadhav)\
**Post date:** [March 14, 2023, 1:09pm UTC](https://forum.ansible.com/t/printing-the-items-on-dictionary-format/37762/2 "2023-03-14T13:09:32Z")

</div>

> Hi

you can try this way

---

<div class="post-metadata">

**Author:** ![Veera](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/veera/32/4107_2.png) [@Veera](https://forum.ansible.com/u/Veera)\
**Post date:** [March 14, 2023, 1:30pm UTC](https://forum.ansible.com/t/printing-the-items-on-dictionary-format/37762/3 "2023-03-14T13:30:44Z")

</div>

Thanks … You mean with the “loop” enabled … It did not work in both modes.

I am looking for a way so that this particular play will process the variables(items) under _n\_america in_  
_vars\_files :_  
_- vars/myvars.yml_

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [March 14, 2023, 6:33pm UTC](https://forum.ansible.com/t/printing-the-items-on-dictionary-format/37762/4 "2023-03-14T18:33:29Z")

</div>

Not sure what you’re trying to do with subelements.  
You could do this:

---

<div class="post-metadata">

**Author:** ![Veera](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/veera/32/4107_2.png) [@Veera](https://forum.ansible.com/u/Veera)\
**Post date:** [March 16, 2023, 6:05pm UTC](https://forum.ansible.com/t/printing-the-items-on-dictionary-format/37762/5 "2023-03-16T18:05:40Z")

</div>

Thanks Todd,

It works .

“Not sure what you’re trying to do with subelements.” - I want to avoid printing messages of other dict items ( asia) from vars during the execution (in the skipping), which prints some sensitive info on the screen.  
Turning on no\_log is not helpful in registering the output.  
So , I was trying to call only the variables under n\_america when I execute the task and i got it . However for now skipping shows the items from asia during the play .
