Skip to content

difference

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 the first list that do not appear in the second one.
  • 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 elements of list1 not in list2
# list1: [1, 2, 5, 1, 3, 4, 10]
# list2: [1, 2, 3, 4, 5, 11, 99]
{{ list1 | difference(list2) }}
# => [10]

Return Values

Key Data Type Description Returned
_value list A unique list of the elements from the first list that do not appear on the second.

Authors

  • Brian Coca (@bcoca)