I am tasked in setting up a check to verify if an IP address is contained within a subnet, with Ansible.
I have set up a test playbook, where I have done the following:
tasks:
- name: "Include_vars"
include_vars:
file: /vlans.yml
- name: "Set_fact"
set_fact:
test_item "{{ item | string | split (':') | last }}"
loop: "{{ vlans }}"
Within the vlans.yml, the file contains a list of VLAN subnets, formatted like this:
vlans:
- "vlan-1-external:10.0.1.0/24"
- "vlan-2-internal:10.0.2.0/24"
[...]
The playbook manages - with a debug instruction - to split the given string and only return the subnet like 10.0.1.0/24.
My objective is to make the playbook evaluate every VLAN within the list, passing an IP as an argument, and returning the specific VLAN which contains that IP address.
I have looked into the ipaddr filter, but I cannot see any way to perform this kind of check.
Does anybody know a way to perform the check that I'm looking for?
Thanks in advance for any hints.