ansible.builtin.combinations filter – combinations from the elements of 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 combinations even without specifying the collections: keyword. However, we recommend you use the FQCN for easy linking to the plugin documentation and to avoid conflicting with other collections that may have the same filter plugin name.

Synopsis

  • Create a list of combinations of sets from the elements of a list.

Input

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

Parameter

Comments

Input

list / elements=string / required

Elements to combine.

Positional parameters

This describes positional parameters of the filter. These are the values positional1, positional2 and so on in the following example: input | ansible.builtin.combinations(positional1, positional2, ...).

Parameter

Comments

set_size

integer / required

The size of the set for each combination.

Examples

# combos_of_two => [ [ 1, 2 ], [ 1, 3 ], [ 1, 4 ], [ 1, 5 ], [ 2, 3 ], [ 2, 4 ], [ 2, 5 ], [ 3, 4 ], [ 3, 5 ], [ 4, 5 ] ]
combos_of_two: "{{ [1,2,3,4,5] | combinations(2) }}"

Return Value

Key

Description

Return value

list / elements=string

List of combination sets resulting from the supplied elements and set size.

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.