# Loop with subelements which is not everytime a list

**URL:** <https://forum.ansible.com/t/loop-with-subelements-which-is-not-everytime-a-list/28454>\
**Category:** Ansible Project\
**Created:** [August 29, 2018, 8:13am UTC](https://forum.ansible.com/t/loop-with-subelements-which-is-not-everytime-a-list/28454 "2018-08-29T08:13:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthias\_Beck](https://avatars.discourse-cdn.com/v4/letter/m/41988e/32.png) [@Matthias\_Beck](https://forum.ansible.com/u/Matthias_Beck)\
**Post date:** [August 29, 2018, 8:13am UTC](https://forum.ansible.com/t/loop-with-subelements-which-is-not-everytime-a-list/28454/1 "2018-08-29T08:13:14Z")

</div>

Hi everyone,

I’m looping over list of servers where I have two items:

svm\_name  
protocols

Protocols can be include one or multiple items:

> ok: [localhost] =\> {  
> “msg”: [  
> {  
> “protocols”: [  
> “nfs”,  
> “cifs”  
> ],  
> “svm\_name”: “90101”  
> },  
> {  
> “protocols”: “fcp”,  
> “svm\_name”: “90100”  
> }  
> ]  
> }

I’m looping through this list to get all the servers, which have cifs activated:

> - name: Create\_list\_of\_CIFS\_SVMs  
> set\_fact:  
> cifs\_servers: “{{ cifs\_svms + [{‘svm\_name’: item.0.svm\_name}] }}”  
> loop: “{{ data\_svms | subelements(‘protocols’) }}”  
> when: item.1 == “cifs”

That loop works if there are multiple items within protocols available. If there is only one item available it fails with fatal:

> [localhost]: FAILED! =\> {“msg”: “the key ‘protocols’ should point to a list, got u’fcp’”}

Does any one have an idea, how to fix this?

Thanks

Matthias
