.. Document meta
:orphan:
.. |antsibull-internal-nbsp| unicode:: 0xA0
:trim:
.. meta::
:antsibull-docs: 2.16.3
.. Anchors
.. _ansible_collections.middleware_automation.amq.lists_mergeby_filter:
.. Anchors: short name for ansible.builtin
.. Title
lists_mergeby -- Merge two or more lists of dictionaries by a given attribute
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
.. Collection note
.. note::
This filter plugin is part of the `middleware_automation.amq collection `_.
It is not included in ``ansible-core``.
To check whether it is installed, run :code:`ansible-galaxy collection list`.
To install it, use: :code:`ansible-galaxy collection install middleware\_automation.amq`.
To use it in a playbook, specify: :code:`middleware_automation.amq.lists_mergeby`.
.. version_added
.. rst-class:: ansible-version-added
New in middleware\_automation.amq 2.0.0
.. contents::
:local:
:depth: 1
.. Deprecated
Synopsis
--------
.. Description
- Merge two or more lists by attribute :ansopt:`middleware\_automation.amq.lists\_mergeby#filter:index`. Optional parameters :ansopt:`middleware\_automation.amq.lists\_mergeby#filter:recursive` and :ansopt:`middleware\_automation.amq.lists\_mergeby#filter:list\_merge` control the merging of the lists in values. The function merge\_hash from ansible.utils.vars is used. To learn details on how to use the parameters :ansopt:`middleware\_automation.amq.lists\_mergeby#filter:recursive` and :ansopt:`middleware\_automation.amq.lists\_mergeby#filter:list\_merge` see Ansible User's Guide chapter "Using filters to manipulate data" section "Combining hashes/dictionaries".
.. Aliases
.. Requirements
.. Input
Input
-----
This describes the input of the filter, the value before ``| middleware_automation.amq.lists_mergeby``.
.. raw:: html
Parameter |
Comments |
Input
list
/ elements=dictionary
/ required
|
|
.. Positional
Positional parameters
---------------------
This describes positional parameters of the filter. These are the values ``positional1``, ``positional2`` and so on in the following
example: ``input | middleware_automation.amq.lists_mergeby(positional1, positional2, ...)``
.. raw:: html
Parameter |
Comments |
another_list
list
/ elements=dictionary
|
Another list of dictionaries. This parameter can be specified multiple times.
|
|
The dictionary key that must be present in every dictionary in every list that is used to merge the lists.
|
.. Options
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 | middleware_automation.amq.lists_mergeby(key1=value1, key2=value2, ...)``
.. raw:: html
Parameter |
Comments |
|
Modifies the behaviour when the dictionaries (hashes) to merge contain arrays/lists.
Choices:
"replace" ← (default)
"keep"
"append"
"prepend"
"append_rp"
"prepend_rp"
|
|
Should the combine recursively merge nested dictionaries (hashes).
Note: It does not depend on the value of the hash_behaviour setting in ansible.cfg .
Choices:
|
.. Attributes
.. Notes
Notes
-----
.. note::
- When keyword and positional parameters are used together, positional parameters must be listed before keyword parameters:
``input | middleware_automation.amq.lists_mergeby(positional1, positional2, key1=value1, key2=value2)``
.. Seealso
.. Examples
Examples
--------
.. code-block:: yaml+jinja
- name: Merge two lists
ansible.builtin.debug:
msg: >-
{{ list1 | middleware_automation.amq.lists_mergeby(
list2,
'index',
recursive=True,
list_merge='append'
) }}"
vars:
list1:
- index: a
value: 123
- index: b
value: 42
list2:
- index: a
foo: bar
- index: c
foo: baz
# Produces the following list of dictionaries:
# {
# "index": "a",
# "foo": "bar",
# "value": 123
# },
# {
# "index": "b",
# "value": 42
# },
# {
# "index": "c",
# "foo": "baz"
# }
.. Facts
.. Return values
Return Value
------------
.. raw:: html
Key |
Description |
Return value
list
/ elements=dictionary
|
The merged list.
Returned: success
|
.. Status (Presently only deprecated)
.. Authors
Authors
~~~~~~~
- Vladimir Botka (@vbotka)
.. hint::
Configuration entries for each entry type have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up.
.. Extra links
.. Parsing errors