Given a list of IP addresses, for example:
ip_addresses:
- 192.168.10.198
- 192.168.52.7
- 192.168.109.78
A list of networks, for example:
valid_networks:
- 192.168.10.0/24
- 192.168.22.0/23
- 192.168.50.0/21
- 192.168.202.0/23
- 192.168.205.0/24
- 192.168.222.0/24
I'd like to assert that all entries in the ip_addresses list are a valid IP in one of the networks in the valid_networks list.
In the above example, it should fail because 192.168.109.78 isn't valid against any of the valid_networks.
Something like this will loop over the nested list and return true or false for each iteration, but I need to turn that into a useful overall pass or fail output. i.e., if there is no true for an IP address, it will fail and return the message “IP address x is not valid”. I'm struggling to come up with the accompanying logic.
- debug:
msg: "{{ item.1 | network_in_usable(item.0) }}"
with_nested:
- "{{ ip_addresses }}"
- "{{ valid_networks }}"
Many thanks in advance.