community.general.random_mac filter – Generate a random MAC address
Note
This filter plugin is part of the community.general collection (version 12.6.1).
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 community.general.
To use it in a playbook, specify: community.general.random_mac.
Synopsis
- Generates random networking interfaces MAC addresses for a given prefix.
Input
This describes the input of the filter, the value before | community.general.random_mac.
Parameter | Comments |
|---|---|
Input string / required | A string prefix to use as a basis for the random MAC generated. |
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 | community.general.random_mac(key1=value1, key2=value2, ...)
Parameter | Comments |
|---|---|
seed string | A randomization seed to initialize the process, used to get repeatable results. If no seed is provided, a system random source such as |
Examples
- name: Random MAC given a prefix
ansible.builtin.debug:
msg: "{{ '52:54:00' | community.general.random_mac }}"
# => '52:54:00:ef:1c:03'
- name: With a seed
ansible.builtin.debug:
msg: "{{ '52:54:00' | community.general.random_mac(seed=inventory_hostname) }}"
Return Value
Key | Description |
|---|---|
Return value string | The generated MAC. Returned: success |
Collection links
© 2012–2018 Michael DeHaan
© 2018–2025 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/projects/ansible/latest/collections/community/general/random_mac_filter.html