# Retrieving items from a dictionary

**URL:** <https://forum.ansible.com/t/retrieving-items-from-a-dictionary/38474>\
**Category:** Ansible Project\
**Created:** [September 27, 2023, 5:11pm UTC](https://forum.ansible.com/t/retrieving-items-from-a-dictionary/38474 "2023-09-27T17:11:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![harry\_devine](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/harry_devine/32/5293_2.png) [@harry\_devine](https://forum.ansible.com/u/harry_devine)\
**Post date:** [September 27, 2023, 5:11pm UTC](https://forum.ansible.com/t/retrieving-items-from-a-dictionary/38474/1 "2023-09-27T17:11:07Z")

</div>

I am trying to look at our server mounts and only show those that have a specific mount available. The playbook is as follows:

---

<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:** [September 27, 2023, 7:32pm UTC](https://forum.ansible.com/t/retrieving-items-from-a-dictionary/38474/2 "2023-09-27T19:32:44Z")

</div>

Map the attribute

&nbsp;&nbsp;dn: "{{ ansible\_mounts|  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;selectattr('device', 'contains', 'nas-server.example.com')|  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;map(attribute='device') }}"

If you want to skip empty lists test the length

&nbsp;&nbsp;- debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var: dn  
&nbsp;&nbsp;&nbsp;&nbsp;when: dn|length \> 0

---

<div class="post-metadata">

**Author:** ![harry\_devine](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/harry_devine/32/5293_2.png) [@harry\_devine](https://forum.ansible.com/u/harry_devine)\
**Post date:** [September 28, 2023, 12:07pm UTC](https://forum.ansible.com/t/retrieving-items-from-a-dictionary/38474/3 "2023-09-28T12:07:05Z")

</div>

Thank you Vladimir! I had already gotten the selectattr piece working but the length check was the missing piece. All good now.

Thanks,  
Harry
