ansible.utils.ipv4_netmask (4.0.0) — test

Test if an address is a valid netmask

| "added in version" 2.2.0 of ansible.utils"

Authors: Priyam Sahoo (@priyamsahoo)

Install collection

Install with ansible-galaxy collection install ansible.utils:==4.0.0


Add to requirements.yml

  collections:
    - name: ansible.utils
      version: 4.0.0

Description

This plugin checks if the provided ip address is a valid IPv4 netmask or not

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.

#### Simple examples

- name: Check if 255.255.255.0 is a netmask
  ansible.builtin.set_fact:
    data: "{{ '255.255.255.0' is ansible.utils.ipv4_netmask }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# TASK [Check if 255.255.255.0 is a netmask] *******************************************
# ok: [localhost] => {
#     "ansible_facts": {
#         "data": true
#     },
#     "changed": false
# }

- name: Check if 255.255.255.128 is a netmask
  ansible.builtin.set_fact:
    data: "{{ '255.255.255.128' is ansible.utils.ipv4_netmask }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# TASK [Check if 255.255.255.128 is a netmask] *****************************************
# ok: [localhost] => {
#     "ansible_facts": {
#         "data": true
#     },
#     "changed": false
# }

- name: Check if 255.255.255.127 is not a netmask
  ansible.builtin.set_fact:
    data: "{{ '255.255.255.127' is not ansible.utils.ipv4_netmask }}"

Inputs

    
mask:
    description:
    - A string that represents the value against which the test is going to be performed
    - 'For example: C(0.1.255.255) or C(255.255.255.0)'
    required: true
    type: str

Outputs

data:
  description:
  - If jinja test satisfies plugin expression C(true)
  - If jinja test does not satisfy plugin expression C(false)