macaddr¶
Collection Note
This module is part of the ansible.utils collection. To install the collection, use:
Added in version2.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.
Parameters¶
| Parameter | Defaults / Choices | Comments |
|---|---|---|
| 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.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 Values¶
| Key | Data Type | Description | Returned |
|---|---|---|---|
| data | str | mac/Hw address |
Authors¶
- Ashwini Mhatre (@amhatre)