community / community.general / 3.8.10 / filter / lists_mergeby Merge two lists of dictionaries by a given attribute | "added in version" 2.0.0 of community.general" Authors: Vladimir Botka (@vbotka)community.general.lists_mergeby (3.8.10) — filter
Install with ansible-galaxy collection install community.general:==3.8.10
collections: - name: community.general version: 3.8.10
Merge two lists by attribute I(index).
- name: Merge two lists ansible.builtin.debug: msg: >- {{ list1 | community.general.lists_mergeby(list2, 'index') }}" vars: list1: - index: a value: 123 - index: b value: 42 list2: - index: a foo: bar - index: c foo: baz
index: description: - The dictionary key that must be present in every dictionary in every list that is used to merge the lists. required: true type: string _input: description: A list of dictionaries. elements: dictionary required: true type: list another_list: description: Another list of dictionaries. elements: dictionary required: true type: list
_value: description: The merged list. elements: dictionary type: list