ansible.builtin.union filter – union of lists

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 union 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.

New in Ansible 1.4

Synopsis

  • Provide a unique list of all the elements of two lists.

Input

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

Parameter

Comments

Input

list / elements=string / required

A list.

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

Parameter

Comments

_second_list

list / elements=string / required

A list.

See Also

See also

ansible.builtin.difference filter plugin

The official documentation on the ansible.builtin.difference filter plugin.

ansible.builtin.intersect filter plugin

The official documentation on the ansible.builtin.intersect filter plugin.

ansible.builtin.symmetric_difference filter plugin

The official documentation on the ansible.builtin.symmetric_difference filter plugin.

ansible.builtin.unique filter plugin

The official documentation on the ansible.builtin.unique filter plugin.

Examples

# return the unique elements of list1 added to list2
# list1: [1, 2, 5, 1, 3, 4, 10]
# list2: [1, 2, 3, 4, 5, 11, 99]
{{ list1 | union(list2) }}
# => [1, 2, 5, 1, 3, 4, 10, 11, 99]

Return Value

Key

Description

Return value

list / elements=string

A unique list of all the elements from both lists.

Returned: success

Authors

  • Brian Coca (@bcoca)

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.