ability to gather CIDR ( /24 aswell as 255.255.255.0) from remote server.

I would like facts to gather CIDR as well as netmask for my IPv4, Its useful for a lot of config files where it doesn’t take 255.255.255.0 but rather only allow /24, like quagga’s ospfd.conf

Sample config:

router ospf

ospf router-id 192.168.0.4
redistribute kernel route-map only-lo
redistribute connected route-map only-lo
network 192.168.0.0/24 area 0.0.0.255

So I want my jinja2 template to have a CIDR variable so I can use:

router ospf
ospf router-id {{ ansible_bond0[‘ipv4’][‘address’] }}
redistribute kernel route-map only-lo
redistribute connected route-map only-lo
network {{ ansible_bond0[‘ipv4’][‘network’] }}{{ ansible_bond0[‘ipv4’][‘cidr’] }} area 0.0.0.255

What do you think?

To me, a filter makes much more sense ipv4_netmask_to_cidr as the information is already there, you just want to change the format

perhaps even just “to_cidr” as a filter.

python-netaddr can do this pretty easily, I would even be ok with adding python-netaddr as a setup.py requirement (though it would be nice if it safely caught the import and let other functions continue to work if not installed, maybe?)