ipaddr: Handle network address in ipmath (#57149)

* Updated testcase, documentation

Fixes: #54457

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
Abhijeet Kasurde
2019-06-04 14:01:19 +05:30
committed by Nilashish Chakraborty
parent e620e27609
commit ee8a607cca
3 changed files with 18 additions and 2 deletions

View File

@@ -673,8 +673,11 @@ def ipaddr(value, query='', version=False, alias='ipaddr'):
def ipmath(value, amount):
try:
ip = netaddr.IPAddress(value)
except netaddr.AddrFormatError:
if '/' in value:
ip = netaddr.IPNetwork(value).ip
else:
ip = netaddr.IPAddress(value)
except (netaddr.AddrFormatError, ValueError):
msg = 'You must pass a valid IP address; {0} is invalid'.format(value)
raise errors.AnsibleFilterError(msg)