This filter is designed to Wrap IPv6 addresses in [ ] brackets.
Version added: 2.5.0
- Some configuration files require IPv6 addresses to be "wrapped" in square brackets ([ ]).To accomplish that,
- you can use the ipwrap() filter.It will wrap all IPv6 addresses and leave any other strings intact.
#### examples
# Ipwrap filter plugin o Wrap IPv6 addresses in [ ] brackets.
- name: Set value as input list
ansible.builtin.set_fact:
value:
- 192.24.2.1
- host.fqdn
- ::1
- ''
- 192.168.32.0/24
- fe80::100/10
- 42540766412265424405338506004571095040/64
- true
- debug:
msg: "{{ value|ansible.utils.ipwrap }}"
- name: |
ipwrap() did not filter out non-IP address values, which is usually what you want when for example
you are mixing IP addresses with hostnames. If you still want to filter out all non-IP address values,
you can chain both filters together.
debug:
msg: "{{ value|ansible.utils.ipaddr|ansible.utils.ipwrap }}"
# PLAY [Ipwrap filter plugin o Wrap IPv6 addresses in [ ] brackets.] ***************************************************
# TASK [Set value as input list] ***************************************************************************************
# ok: [localhost] => {"ansible_facts": {"value": ["192.24.2.1", "host.fqdn", "::1", "", "192.168.32.0/24",
# "fe80::100/10", "42540766412265424405338506004571095040/64", true]}, "changed": false}
#
# TASK [debug] ********************************************************************************************************
# ok: [localhost] => {
# "msg": [
# "192.24.2.1",
# "::1",
# "192.168.32.0/24",
# "fe80::100/10",
# "2001:db8:32c:faad::/64"
# ]
# }
#
# TASK [debug] ************************************************************************************************
# ok: [localhost] => {
# "msg": [
# "192.24.2.1",
# "host.fqdn",
# "[::1]",
# "",
# "192.168.32.0/24",
# "[fe80::100]/10",
# "[2001:db8:32c:faad::]/64",
# "True"
# ]
# }
#
# TASK [ipwrap() did not filter out non-IP address values, which is usually what you want when for example
# you are mixing IP addresses with hostnames. If you still want to filter out all non-IP address values,
# you can chain both filters together.] ***
# ok: [localhost] => {
# "msg": [
# "192.24.2.1",
# "[::1]",
# "192.168.32.0/24",
# "[fe80::100]/10",
# "[2001:db8:32c:faad::]/64"
# ]
# }
Common return values are documented here, the following are the fields unique to this filter:
Key | Returned | Description |
---|---|---|
data
raw
|
Returns values valid for a particular query.
|
- Ashwini Mhatre (@amhatre)
Hint
Configuration entries for each entry type have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up.