Best way to get at CIDR netmask data? (i.e. "/24" rather than 255.255.255.0)

Hello folks,

Following up on https://github.com/ansible/ansible/issues/8584, wanted to open a discussion on the best way to be able to get at CIDR formatted netmask info.

If a host fact returns a netmask 255.255.255.0, I’d like to find a way to convert that to “24” - some config files such as Postgres pg_hba.conf require CIDR format.

I was able to create a custom Jinja2 filter (referenced in the issue above) and pasted below - would it make sense to incorporate such a filter into the standard Ansible codebase? Is there a better approach?

Regards,
–Ed

The above looks pretty good to me.

python-netaddr should be available most anywhere, and I wouldn’t object to it being a dependency, and I think we’d want to use that if possible.

Hi,

Will this filter be added in next release ?

what is the status on this ?

regards,

Julien.

AFAIK, there have been no submissions for any CIDR-related filters at this time.

Still open to them!

Hi all,

my first post here ever.

I’ve been looking all over for this feature… Is this implemented yet in ansible v2? It would be great to have it in ansible. In my setting, this format is required by Postgresql’s pg_hba.conf and Pacemaker’s script to configure virtual ips in Debian HA.

Pada Rabu, 08 Oktober 2014 19.49.08 UTC+7, michael menulis:

Never mind! I finally have a satisfying answer.

It’s a work-around just recently explained (23 days ago) by jtognazzi:
{{ ‘X/255.255.255.0’ | ipaddr(‘prefix’) }}
gives:
24
Where X is a dummy ip.

Thanks anyway! ansible is an awesome project!

Pada Rabu, 08 Oktober 2014 19.49.08 UTC+7, michael menulis: