ansible.builtin.shuffle filter – randomize a list

Note

This filter plugin is part of ansible-core and included in all Ansible installations. In most cases, you can use the short plugin name shuffle. However, we recommend you use the Fully Qualified Collection Name (FQCN) ansible.builtin.shuffle for easy linking to the plugin documentation and to avoid conflicting with other collections that may have the same filter plugin name.

Synopsis

  • Take the elements of the input list and return in a random order.

Input

This describes the input of the filter, the value before | ansible.builtin.shuffle.

Parameter

Comments

Input

list / elements=any / required

A number or list to randomize.

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

Parameter

Comments

seed

string

If specified use a pseudo random selection instead (repeatable).

Examples

randomized_list: "{{ ['a','b','c'] | shuffle}}"
per_host_repeatable: "{{ ['a','b','c'] | shuffle(seed=inventory_hostname) }}"

Return Value

Key

Description

Return value

list / elements=any

Random number or list element.

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.