ansible.utils.ipcut filter – This filter is designed to get 1st or last few bits of IP address.
Note
This filter plugin is part of the ansible.utils collection (version 5.1.2).
You might already have this collection installed if you are using the ansible
package.
It is not included in ansible-core
.
To check whether it is installed, run ansible-galaxy collection list
.
To install it, use: ansible-galaxy collection install ansible.utils
.
To use it in a playbook, specify: ansible.utils.ipcut
.
New in ansible.utils 2.11.0
Synopsis
This filter is designed to fetch 1st or last few bits of Ip address.
Keyword parameters
This describes keyword parameters of the filter. These are the values key1=value1
, key2=value2
and so on in the following
example: input | ansible.utils.ipcut(key1=value1, key2=value2, ...)
Parameter |
Comments |
---|---|
integer for arithmetic. Example -1,2,3 |
|
list of subnets or individual address or any other values input for ip_cut plugin |
Examples
#### examples
- name: Get first 64 bits of Ipv6 address
debug:
msg: "{{ '1234:4321:abcd:dcba::17' | ansible.utils.ipcut(64) }}"
- name: Get last 80 bits of Ipv6 address
debug:
msg: "{{ '1234:4321:abcd:dcba::17' | ansible.utils.ipcut(-80) }}"
# PLAY [IPCUT filter plugin examples] ************************************************************************************************
# TASK [Get first X bits of Ipv6 address] ********************************************************************************************
# ok: [localhost] => {
# "msg": "1234:4321:abcd:dcba"
# }
# TASK [Get last X bits of Ipv6 address] *********************************************************************************************
# ok: [localhost] => {
# "msg": "dcba:0:0:0:17"
# }
# PLAY RECAP *************************************************************************************************************************
# localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Return Value
Key |
Description |
---|---|
Returns result of portion of IP. Returned: success |