Skip to content

intersect

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 list with the common elements from other 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 only the common elements of list1 and list2
# list1: [1, 2, 5, 3, 4, 10]
# list2: [1, 2, 3, 4, 5, 11, 99]
{{ list1 | intersect(list2) }}
# => [1, 2, 5, 3, 4]

Return Values

Key Data Type Description Returned
_value list A list with unique elements common to both lists, also known as a set.

Authors

  • Brian Coca (@bcoca)