community / community.general / 8.5.0 / filter / lists_union Union of lists with a predictive order | "added in version" 8.4.0 of community.general" Authors: Christoph Fiehe (@cfiehe)community.general.lists_union (8.5.0) — filter
Install with ansible-galaxy collection install community.general:==8.5.0
collections: - name: community.general version: 8.5.0
Provide a unique list of all the elements of two or more lists.
The order of the items in the resulting list is preserved.
- 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]
_input: description: A list. elements: any required: true type: list flatten: default: false description: Whether to remove one hierarchy level from the input list. type: boolean
_value: description: A unique list of all the elements from the provided lists. elements: any type: list