community.general.random_mac filter – Generate a random MAC address

Note

This filter plugin is part of the community.general collection (version 7.5.2).

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 /dev/urandom is used.

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

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.