I have a json data structure that looks like this.
"napalm_interfaces_ip": {
"GigabitEthernet0/0": {
"ipv4": {
"10.23.160.110": {
"prefix_length": 22
},
"10.23.160.114": {
"prefix_length": 22
}
}
},
"GigabitEthernet1/0/1": {
"ipv4": {
"10.23.160.112": {
"prefix_length": 22
}
}
}
},
I want to use Ansible to find the interface that has a specific IP address assigned.
I thought I could use with_dict to loop through the dictionary and when to find the interface with the IP that matches. Something like this...
- name: Testing with_dict
debug:
msg: "Interface is {{ item.key }}"
when: 10.23.160.114 == item.value.ipv4.keys()
with_dict: "{{ napalm_device_data.ansible_facts.napalm_interfaces_ip }}"
This isn't going to work though as item.value.ipv4 is a dictionary and really what I want to do is compare each of the keys in item.value.ipv4 against the IP address. I think i need a way to loop through the dictionary within the dictionary but I'm not 100% sure.
I do not want to flatten the data structure. I am just looking for a way to reference the key of a dictionary within a dictionary.
Any help is much appreciated.