regex to match name of include file

Initial posts to the list are moderated, so that would explain the delay (I see it now)…

There are two solutions to your question, but I think the easiest one is actually the best…

In your case rename your files to (for example) 10.18.101.0.yml and use - include_vars: “{{ ansible_default_ipv4.network }}.yml”

This WILL work for all networks that you have as when your netmask is not 255.255.255.0 then the network itself will change. The only time that you might have issues is if you (for some reason) have machines on the same physical network with different netmasks. If that is the case then you should probably just fix your machines.

Here are some examples of IP address 10.18.101.129 with different netmasks…
/8 10.0.0.0 (16,777,214 hosts)
/16 10.18.0.0 (65,534 hosts)
/24 10.18.101.0 (254 hosts)
/25 10.18.101.128 (126 hosts)
/26 10.18.101.128 (62 hosts)

Note that the last two are identical because we are now at the start of the net block…

Adam

Hi Adam, thanks for the reply.

I had actually already ended up doing exactly as you suggested.

Out of interest what was the second solution? Is there a way to easily manipulate the network address as I first intended?

You could use {{ ansible_default_ipv4.network.split(‘.’) }} to get individual octets…

It’s a lot messier and less reliable, but there you go.

Adam