From 73766e08168c23b74e71c7d8e86ad517d9ba5e6c Mon Sep 17 00:00:00 2001 From: Mark Janssen -- Sig-I/O Automatisering Date: Fri, 25 Mar 2016 15:24:48 +0100 Subject: [PATCH 1/2] Add ip4_hex filter to convert ip-address to hex notation --- lib/ansible/plugins/filter/ipaddr.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/ansible/plugins/filter/ipaddr.py b/lib/ansible/plugins/filter/ipaddr.py index 432de6031b1..7ea55b30ad7 100644 --- a/lib/ansible/plugins/filter/ipaddr.py +++ b/lib/ansible/plugins/filter/ipaddr.py @@ -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, From b1015d897d5adfc1cb07dd773e1a2247974ac38c Mon Sep 17 00:00:00 2001 From: Mark Janssen -- Sig-I/O Automatisering Date: Fri, 25 Mar 2016 15:33:35 +0100 Subject: [PATCH 2/2] Re-add accidentaly removed comment --- lib/ansible/plugins/filter/ipaddr.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/ansible/plugins/filter/ipaddr.py b/lib/ansible/plugins/filter/ipaddr.py index 7ea55b30ad7..bfcf32af051 100644 --- a/lib/ansible/plugins/filter/ipaddr.py +++ b/lib/ansible/plugins/filter/ipaddr.py @@ -675,6 +675,7 @@ def ip4_hex(arg): numbers = list(map(int, arg.split('.'))) return '{:02x}{:02x}{:02x}{:02x}'.format(*numbers) +# ---- Ansible filters ---- class FilterModule(object): ''' IP address and network manipulation filters '''