Skip to content

reduce_on_network

Collection Note

This module is part of the ansible.utils collection. To install the collection, use:

ansible-galaxy collection install ansible.utils
Added in version 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.

Parameters

Parameter Defaults / Choices Comments
network
str
The network to validate against.
value
list / elements=str
required
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 Values

Key Data Type Description Returned
data bool Returns whether an address or a network passed as argument is in a network.

Authors

  • Ashwini Mhatre (@amhatre)