mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
102a0857db
New filters lists_union, lists_intersect, lists_difference and lists_symmetric_difference added. Signed-off-by: Christoph Fiehe <c.fiehe@eurodata.de> Co-authored-by: Christoph Fiehe <c.fiehe@eurodata.de>
48 lines
1.5 KiB
YAML
48 lines
1.5 KiB
YAML
---
|
|
# Copyright (c) Ansible Project
|
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
DOCUMENTATION:
|
|
name: lists_difference
|
|
short_description: Difference of lists with a predictive order
|
|
version_added: 8.4.0
|
|
description:
|
|
- 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.
|
|
options:
|
|
_input:
|
|
description: A list.
|
|
type: list
|
|
elements: any
|
|
required: true
|
|
flatten:
|
|
description: Whether to remove one hierarchy level from the input list.
|
|
type: boolean
|
|
default: false
|
|
author:
|
|
- Christoph Fiehe (@cfiehe)
|
|
|
|
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:
|
|
description: A unique list of all the elements from the first list that do not appear on the other lists.
|
|
type: list
|
|
elements: any
|