community.general.lists_symmetric_difference filter – Symmetric Difference of lists with a predictive order

Note

This filter plugin is part of the community.general collection (version 9.4.0).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.general.

To use it in a playbook, specify: community.general.lists_symmetric_difference.

New in community.general 8.4.0

Synopsis

  • Provide a unique list containing the symmetric difference of two or more lists.

  • The order of the items in the resulting list is preserved.

Input

This describes the input of the filter, the value before | community.general.lists_symmetric_difference.

Parameter

Comments

Input

list / elements=any / 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 | community.general.lists_symmetric_difference(key1=value1, key2=value2, ...)

Parameter

Comments

flatten

boolean

Whether to remove one hierarchy level from the input list.

Choices:

  • false ← (default)

  • true

Examples

- name: Return the symmetric difference of list1 and list2.
  ansible.builtin.debug:
    msg: "{{ list1 | community.general.lists_symmetric_difference(list2) }}"
  vars:
    list1: [1, 2, 5, 3, 4, 10]
    list2: [1, 2, 3, 4, 5, 11, 99]
# => [10, 11, 99]

- name: Return the symmetric difference of list1, list2 and list3.
  ansible.builtin.debug:
    msg: "{{ [list1, list2, list3] | community.general.lists_symmetric_difference(flatten=true) }}"
  vars:
    list1: [1, 2, 5, 3, 4, 10]
    list2: [1, 2, 3, 4, 5, 11, 99]
    list3: [1, 2, 3, 4, 5, 10, 99, 101]
# => [11, 1, 2, 3, 4, 5, 101]

Return Value

Key

Description

Return value

list / elements=any

A unique list containing the symmetric difference of two or more lists.

Returned: success

Authors

  • Christoph Fiehe (@cfiehe)

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.