community.general.lists_difference filter – Difference of lists with a predictive order
Note
This filter plugin is part of the community.general collection (version 9.4.0).
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_difference
.
New in community.general 8.4.0
Synopsis
Provide a unique list of all the elements from the first which do not appear in the other 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_difference
.
Parameter |
Comments |
---|---|
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_difference(key1=value1, key2=value2, ...)
Parameter |
Comments |
---|---|
Whether to remove one hierarchy level from the input list. Choices:
|
Examples
- name: Return the difference of list1 and list2.
ansible.builtin.debug:
msg: "{{ list1 | community.general.lists_difference(list2) }}"
vars:
list1: [1, 2, 5, 3, 4, 10]
list2: [1, 2, 3, 4, 5, 11, 99]
# => [10]
- name: Return the difference of list1, list2 and list3.
ansible.builtin.debug:
msg: "{{ [list1, list2, list3] | community.general.lists_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]
# => []
Return Value
Key |
Description |
---|---|
A unique list of all the elements from the first list that do not appear on the other lists. Returned: success |