ansible.utils.reduce_on_network filter – This filter reduces a list of addresses to only the addresses that match a given network.
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.reduce_on_network
.
New in ansible.utils 2.5.0
Synopsis
This filter reduces a list of addresses to only the addresses that match a given network.
To check whether multiple addresses belong to a network, use the reduce_on_network filter.
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.reduce_on_network(key1=value1, key2=value2, ...)
Parameter |
Comments |
---|---|
The network to validate against. |
|
the list of addresses to filter on. |
Examples
- name: To check whether multiple addresses belong to a network, use the reduce_on_network filter.
debug:
msg: "{{ ['192.168.0.34', '10.3.0.3', '192.168.2.34'] | ansible.utils.reduce_on_network( '192.168.0.0/24' ) }}"
# TASK [To check whether multiple addresses belong to a network, use the reduce_on_network filter.] ***********
# task path: /Users/amhatre/ansible-collections/playbooks/test_reduce_on_network.yaml:7
# Loading collection ansible.utils from /Users/amhatre/ansible-collections/collections/ansible_collections/ansible/utils
# ok: [localhost] => {
# "msg": [
# "192.168.0.34"
# ]
# }
Return Value
Key |
Description |
---|---|
Returns whether an address or a network passed as argument is in a network. Returned: success |