Skip to content

hwaddr

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 check if string is a HW/MAC address and filter it
  • You can use the hwaddr() filter to check if a given string is a MAC address or convert it between various formats.

Parameters

Parameter Defaults / Choices Comments
alias
str
Default: hwaddr
alias
query
str
query string. Example. cisco,linux,unix etc
value
str
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.hwaddr }}"

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

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

Return Values

Key Data Type Description Returned
data str mac/Hw address

Authors

  • Ashwini Mhatre (@amhatre)