Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using netaddr in Jinja with /32 prefixed address leaves netmask empty #17624

Closed
ghost opened this issue Sep 17, 2016 · 1 comment · Fixed by #47539
Closed

Using netaddr in Jinja with /32 prefixed address leaves netmask empty #17624

ghost opened this issue Sep 17, 2016 · 1 comment · Fixed by #47539
Assignees
Labels
affects_2.1 This issue/PR affects Ansible v2.1 bug This issue/PR relates to a bug. in progress

Comments

@ghost
Copy link

ghost commented Sep 17, 2016

ISSUE TYPE
  • Bug Report
COMPONENT NAME

Jinja2 ipaddr() filter

ANSIBLE VERSION
ansible 2.1.1.0
  config file = /Users/Yves/Development/dock42-ansible/ansible.cfg
  configured module search path = Default w/o overrides
CONFIGURATION

N/A

OS / ENVIRONMENT
OS X Yosemite 10.10.5 (14F1909)

14.5.0 Darwin Kernel Version 14.5.0: Thu Jun 16 19:58:21 PDT 2016; root:xnu-2782.50.4~1/RELEASE_X86_64 x86_64

Python 2.7.10
netaddr 0.7.18

##### SUMMARY
When specifying an address which is prefixed with /32 then the Jinja filter just renders an empty string. Also the Jinja filter does not allow prefixlen as query method - even if the locally installed version supports this method.

netaddr seems to work correctly.

##### STEPS TO REPRODUCE

Try to render this:

{{ 192.168.0.1/32 | ipaddr('netmask') }}
EXPECTED RESULTS
{{ 192.168.0.1/32 | ipaddr('netmask') }}
#255.255.255.255
ACTUAL RESULTS
{{ 192.168.0.1/32 | ipaddr('netmask') }}
# <empty>

I verified that netaddr is working correctly.

$ python -i
Python 2.7.10 (default, Jul 14 2015, 19:46:27) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from netaddr import *
>>> ip = IPNetwork('192.0.0.1/32')
>>> ip.netmask
IPAddress('255.255.255.255')
>>> ip.prefixlen
32
>>> ip = IPNetwork('192.0.0.1/24')
>>> ip.netmask

When trying larger prefix length that 32 it works correctly.

{{ 192.168.0.1/24 | ipaddr('netmask') }}
#255.255.255.0

Also I noticed that prefixlen is not supported as method.

prefixlen={{ ipv4 | ipaddr('prefixlen') }} 
# AnsibleFilterError: ipaddr: unknown filter type: prefixlen
@mscherer
Copy link
Contributor

https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/filter/ipaddr.py#L166

The size of the network is verified, and if there is nothing in the network, then we return nothing. I am not sure to understand the reasoning here.

mscherer added a commit to mscherer/ansible that referenced this issue Sep 17, 2016
Even if the size of the network is 0, it should have a netmask.
@ansibot ansibot added bug_report affects_2.1 This issue/PR affects Ansible v2.1 labels Sep 18, 2016
sereinity pushed a commit to sereinity-forks/ansible that referenced this issue Jan 25, 2017
Even if the size of the network is 0, it should have a netmask.
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@ansible ansible locked and limited conversation to collaborators Apr 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.1 This issue/PR affects Ansible v2.1 bug This issue/PR relates to a bug. in progress
Projects
None yet
3 participants