ansible.utils.macaddr (4.0.0) — filter

macaddr / MAC address filters

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

Authors: Ashwini Mhatre (@amhatre)

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 filter check if string is a MAC address and filter it

You can use the macaddr() filter to check if a given string is a MAC address or convert it between various formats.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
#### examples
- name: Check if given string is a MAC address
  debug:
    msg: "{{ '1a:2b:3c:4d:5e:6f' | ansible.utils.macaddr }}"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Convert MAC address to Cisco format
  debug:
    msg: "{{ '1a:2b:3c:4d:5e:6f' | ansible.utils.macaddr('cisco') }}"

Inputs

    
query:
    default: ''
    description: query string. Example. cisco,linux,unix etc
    type: str

value:
    description: HW/MAC address.
    required: true
    type: str

Outputs

data:
  description:
  - mac/Hw address
  type: str