Skip to content

union

Collection Note

This module is part of the ansible.builtin collection. To install the collection, use:

ansible-galaxy collection install ansible.builtin
Added in version 1.4.

Synopsis

  • Provide a unique list of all the elements of two lists.
  • Items in the resulting list are returned in arbitrary order.

Parameters

Parameter Defaults / Choices Comments
_input
list
required
A list.
_second_list
list
required
A list.

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, 3, 4, 10, 11, 99]

Return Values

Key Data Type Description Returned
_value list A unique list of all the elements from both lists.

Authors

  • Brian Coca (@bcoca)