Loop with subelements which is not everytime a list

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