# Issue in with\_nested loop having single Iteration

**URL:** <https://forum.ansible.com/t/issue-in-with-nested-loop-having-single-iteration/36650>\
**Category:** Ansible Developer\
**Created:** [May 23, 2022, 10:51am UTC](https://forum.ansible.com/t/issue-in-with-nested-loop-having-single-iteration/36650 "2022-05-23T10:51:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anirudh\_Gupta](https://avatars.discourse-cdn.com/v4/letter/a/b5a626/32.png) [@Anirudh\_Gupta](https://forum.ansible.com/u/Anirudh_Gupta)\
**Post date:** [May 23, 2022, 10:51am UTC](https://forum.ansible.com/t/issue-in-with-nested-loop-having-single-iteration/36650/1 "2022-05-23T10:51:51Z")

</div>

Hi Team

I am calling a simple function

- name: Setting vm key value  
set\_fact:  
vm\_key: “{{ item.1.key }}”  
when: item.0.key == item.1.value.name  
with\_nested:

- “{{ ia\_hosts\_copy }}”

- “{{ vm\_copy }}”

where

- name: Creating list of sm\_hosts  
set\_fact:  
ia\_hosts\_copy: “{{ lookup(‘dict’, sm\_list) }}”

In case there is only 1 item is defined in the list, ansible gives the error

“ansible\_facts”: {  
“ia\_hosts\_copy”: {  
“key”: “j3chysr01stg05”,  
“value”: {  
“globalDeviceId”: “”,  
“vrrp”: {  
“associated\_sm”: [  
“103”  
]  
}  
}  
}  
},

fatal: [j3chysr01stg05]: FAILED! =\> {“msg”: “The task includes an option with an undefined variable. The error was: ‘ansible.utils.unsafe\_proxy.AnsibleUnsafeText object’ has no attribute ‘key’\n\nThe error appears to be in ‘/import/software/test.yml’: line 35, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Setting vm key value \n ^ here\n”}

**The code works fine, if minimum 2 item are defined in ia\_hosts\_copy**
