ansible.utils.macaddr filter – macaddr / MAC address filters

Note

This filter plugin is part of the ansible.utils collection (version 2.12.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.macaddr.

New in ansible.utils 2.5.0

Synopsis

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

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

Parameter

Comments

query

string

query string. Example. cisco,linux,unix etc

Default: ""

value

string / required

HW/MAC address.

Examples

#### examples
- name: Check if given string is a MAC address
  debug:
    msg: "{{ '1a:2b:3c:4d:5e:6f' | ansible.utils.macaddr }}"

- name: Convert MAC address to Cisco format
  debug:
    msg: "{{ '1a:2b:3c:4d:5e:6f' | ansible.utils.macaddr('cisco') }}"

# TASK [Check if given string is a MAC address] ***************************************************************
# ok: [localhost] => {
#     "msg": "1a:2b:3c:4d:5e:6f"
# }
#
# TASK [Convert MAC address to Cisco format] ******************************************************************
# ok: [localhost] => {
#     "msg": "1a2b.3c4d.5e6f"
# }

Return Value

Key

Description

data

string

mac/Hw address

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.