mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #15159 from sigio/filter-ip4-hex
Add ip4_hex filter to convert ip-address to hex notation
This commit is contained in:
commit
c303ed24b5
1 changed files with 6 additions and 0 deletions
|
@ -670,6 +670,11 @@ def _need_netaddr(f_name, *args, **kwargs):
|
||||||
raise errors.AnsibleFilterError('The {0} filter requires python-netaddr be'
|
raise errors.AnsibleFilterError('The {0} filter requires python-netaddr be'
|
||||||
' installed on the ansible controller'.format(f_name))
|
' installed on the ansible controller'.format(f_name))
|
||||||
|
|
||||||
|
def ip4_hex(arg):
|
||||||
|
''' Convert an IPv4 address to Hexadecimal notation '''
|
||||||
|
numbers = list(map(int, arg.split('.')))
|
||||||
|
return '{:02x}{:02x}{:02x}{:02x}'.format(*numbers)
|
||||||
|
|
||||||
# ---- Ansible filters ----
|
# ---- Ansible filters ----
|
||||||
|
|
||||||
class FilterModule(object):
|
class FilterModule(object):
|
||||||
|
@ -683,6 +688,7 @@ class FilterModule(object):
|
||||||
'ipsubnet': ipsubnet,
|
'ipsubnet': ipsubnet,
|
||||||
'nthhost': nthhost,
|
'nthhost': nthhost,
|
||||||
'slaac': slaac,
|
'slaac': slaac,
|
||||||
|
'ip4_hex': ip4_hex,
|
||||||
|
|
||||||
# MAC / HW addresses
|
# MAC / HW addresses
|
||||||
'hwaddr': hwaddr,
|
'hwaddr': hwaddr,
|
||||||
|
|
Loading…
Reference in a new issue