Add ip4_hex filter to convert ip-address to hex notation

This commit is contained in:
Mark Janssen -- Sig-I/O Automatisering 2016-03-25 15:24:48 +01:00
parent 687c290e1b
commit 73766e0816

View file

@ -670,7 +670,11 @@ def _need_netaddr(f_name, *args, **kwargs):
raise errors.AnsibleFilterError('The {0} filter requires python-netaddr be'
' installed on the ansible controller'.format(f_name))
# ---- Ansible filters ----
def ip4_hex(arg):
''' Convert an IPv4 address to Hexadecimal notation '''
numbers = list(map(int, arg.split('.')))
return '{:02x}{:02x}{:02x}{:02x}'.format(*numbers)
class FilterModule(object):
''' IP address and network manipulation filters '''
@ -683,6 +687,7 @@ class FilterModule(object):
'ipsubnet': ipsubnet,
'nthhost': nthhost,
'slaac': slaac,
'ip4_hex': ip4_hex,
# MAC / HW addresses
'hwaddr': hwaddr,