- name: Create Simple list from Connection Dict
set_fact:
connections: "{{ connections | default([]) + [ {
'switchid': item.id,
'connectionid': item.connections[0].id
} ] }}"
when: item.connections #only want to create facts if connections exist
loop: "{{ connections_result.json.0.switchPorts | flatten }}"
when: connections_result is defined #depending on the host,connection_result.json may not be defined so need to check[WARNING]: While constructing a mapping from /home/xxx/xxxxx.yml, line 245, column 5, found a duplicate dict key (when). Using last defined value only.