# Subelements with the query plugin

**URL:** <https://forum.ansible.com/t/subelements-with-the-query-plugin/27565>\
**Category:** Ansible Project\
**Created:** [May 18, 2018, 10:39pm UTC](https://forum.ansible.com/t/subelements-with-the-query-plugin/27565 "2018-05-18T22:39:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![K\_de\_Jong](https://avatars.discourse-cdn.com/v4/letter/k/51bf81/32.png) [@K\_de\_Jong](https://forum.ansible.com/u/K_de_Jong)\
**Post date:** [May 18, 2018, 10:39pm UTC](https://forum.ansible.com/t/subelements-with-the-query-plugin/27565/1 "2018-05-18T22:39:21Z")

</div>

I’m trying to figure out how to do ‘subelements’ with the query plugin. The thing below doesn’t work, it complains that “could not find ‘ssh\_key’ key in iterated item”. So the skip\_missing is not working. While when I use ‘with\_subelements’ it does work. Can someone see what I’m doing wrong?

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [May 19, 2018, 11:29am UTC](https://forum.ansible.com/t/subelements-with-the-query-plugin/27565/2 "2018-05-19T11:29:15Z")

</div>

Hi,

> I'm trying to figure out how to do 'subelements' with the query  
> plugin. The thing below doesn't work, it complains that "could not  
> find 'ssh\_key' key in iterated item". So the skip\_missing is not  
> working. While when I use 'with\_subelements' it does work. Can  
> someone see what I'm doing wrong?
> 
> \> - name: debug user struct  
> \> debug:  
> \> msg: "{{ item.1 }}"  
> \> loop: "{{ query('subelements', user, 'ssh\_key', skip\_missing=yes) }}"  
> \> tags: test29

According to the documentation (see last example here:  
[https://docs.ansible.com/ansible/2.5/plugins/lookup/subelements.html#examples](https://docs.ansible.com/ansible/2.5/plugins/lookup/subelements.html#examples))  
you need to quote skip\_missing=yes:

> - name: debug user struct  
> &nbsp;&nbsp;debug:  
> &nbsp;&nbsp;&nbsp;&nbsp;msg: "{{ item.1 }}"  
> &nbsp;&nbsp;loop: "{{ query('subelements', user, 'ssh\_key', 'skip\_missing=yes') }}"  
> &nbsp;&nbsp;tags: test29

(Haven't tried it, though.)

Cheers,  
Felix
