1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/plugins/filter/lists_union.yml
cfiehe 102a0857db
New filters to calculate the union, intersection, difference and symmetric difference of lists by preserving the items order (#7985)
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>
2024-02-23 20:35:09 +01:00

48 lines
1.4 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_union
short_description: Union of lists with a predictive order
version_added: 8.4.0
description:
- Provide a unique list of all the elements of two or more 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 union of list1, list2 and list3.
ansible.builtin.debug:
msg: "{{ list1 | community.general.lists_union(list2, list3) }}"
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]
# => [1, 2, 5, 3, 4, 10, 11, 99, 101]
- name: Return the union of list1 and list2.
ansible.builtin.debug:
msg: "{{ [list1, list2] | community.general.lists_union(flatten=true) }}"
vars:
list1: [1, 2, 5, 3, 4, 10]
list2: [1, 2, 3, 4, 5, 11, 99]
# => [1, 2, 5, 3, 4, 10, 11, 99]
RETURN:
_value:
description: A unique list of all the elements from the provided lists.
type: list
elements: any