ansible.utils.network_in_network filter – This filter returns whether an address or a network passed as argument is in a network.

Note

This filter plugin is part of the ansible.utils collection (version 2.8.0).

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.network_in_network.

New in ansible.utils 2.5.0

Synopsis

  • This filter returns whether an address or a network passed as argument is in a network.

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.network_in_network(key1=value1, key2=value2, ...).

Parameter

Comments

test

string

The address or network to validate if it is within the range of ‘value’.

value

string / required

The network address or range to test against.

Examples

#### examples
- name: Check ip address 1 is part of another network
  debug:
    msg: "{{ '192.168.0.0/24' | ansible.utils.network_in_network( '192.168.0.1' ) }}"

- name: Check ip address 2 is part of another network
  debug:
    msg: "{{ '192.168.0.0/24' | ansible.utils.network_in_network( '10.0.0.1' ) }}"

- name: Check in a network is part of another network.
  debug:
    msg: "{{ '192.168.0.0/16' | ansible.utils.network_in_network( '192.168.0.0/24' ) }}"

# TASK [Check ip address 1 is part of another network] ********************************************************
# task path: /Users/amhatre/ansible-collections/playbooks/test_network_in_network.yaml:7
# Loading collection ansible.utils from /Users/amhatre/ansible-collections/collections/ansible_collections/ansible/utils
# ok: [localhost] => {
#     "msg": true
# }
#
# TASK [Check ip address 2 is part of another network] ********************************************************
# task path: /Users/amhatre/ansible-collections/playbooks/test_network_in_network.yaml:11
# Loading collection ansible.utils from /Users/amhatre/ansible-collections/collections/ansible_collections/ansible/utils
# ok: [localhost] => {
#     "msg": false
# }
#
# TASK [Check in a network is part of another network.] *******************************************************
# task path: /Users/amhatre/ansible-collections/playbooks/test_network_in_network.yaml:15
# Loading collection ansible.utils from /Users/amhatre/ansible-collections/collections/ansible_collections/ansible/utils
# ok: [localhost] => {
#     "msg": true
# }

Return Value

Key

Description

data

boolean

Returns whether an address or a network passed as argument is in a network.

Returned: success

Authors

  • 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.