Convert ipv6 addresses to compressed, expanded and special forms
ivanov17 opened this issue · 1 comments
SUMMARY
I was surprised that there is no filter for getting expanded ipv6 addresses in ansible.utils
collection.
I would like to get something as:
# {{ '::1' | ansible.utils.ipv6('expand') }}
'0000:0000:0000:0000:0000:0000:0000:0001'
And for ipv6 addresses compression:
# {{ '0000:0000:0000:0000:0000:0000:0000:0001' | ansible.utils.ipv6('compress') }}
'::1'
Also I think it would be great to have filter that converts ipv6 address to x509 notation:
# {{ '::1' | ansible.utils.ipv6('x509') }}
'0:0:0:0:0:0:0:1'
When the subjectAltName extension contains an iPAddress, the address MUST be stored in the octet string in "network byte order", as specified in [RFC791]. The least significant bit (LSB) of each octet is the LSB of the corresponding byte in the network address. For IP version 4, as specified in [RFC791], the octet string MUST contain exactly four octets. For IP version 6, as specified in [RFC2460], the octet string MUST contain exactly sixteen octets.
IPv6 addresses must be in the form
x:x:x:x:x:x:x:x
, exactly 8 groups of one to four hexadecimal digits separated by colons. The compressed zero form using "::" is not accepted.
ISSUE TYPE
- Feature Idea
COMPONENT NAME
I think it would be like ansible.utils.ip4_hex
filter or ansible.utils.ipwrap
wrapper.
It can be also implemented as separate module, e.g. ansible.utils.ip6_form
:
ansible.utils.ip6_form('compress')
ansible.utils.ip6_form('expand')
ansible.utils.ip6_form('x509')
ADDITIONAL INFORMATION
In general, for processing ipv6 addresses in different forms with other filters. In particular, x509 notation filter for ipv6 will be used for self-signed certificates. Getting expanded ipv6 using regular expressions is a very complicated and unreliable way.
Example of using:
- community.crypto.openssl_csr_pipe:
privatekey_path: "{{ privkey.filename }}"
common_name: "{{ ansible_fqdn }}"
subject_alt_name:
- "IP:{{ ansible_default_ipv4.address }}"
- "IP:{{ ansible_default_ipv6.address|ansible.utils.ip6_form('x509') }}"
#295 is merged