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