ansible.builtin.rekey_on_member filter – Rekey a list of dicts into a dict using a member

Note

This filter plugin is part of ansible-core and included in all Ansible installations. In most cases, you can use the short plugin name rekey_on_member. However, we recommend you use the Fully Qualified Collection Name (FQCN) ansible.builtin.rekey_on_member for easy linking to the plugin documentation and to avoid conflicting with other collections that may have the same filter plugin name.

New in ansible-core 2.13

Synopsis

  • Iterate over several iterables in parallel, producing tuples with an item from each one.

Input

This describes the input of the filter, the value before | ansible.builtin.rekey_on_member.

Parameter

Comments

Input

dictionary / required

Original dictionary.

Positional parameters

This describes positional parameters of the filter. These are the values positional1, positional2 and so on in the following example: input | ansible.builtin.rekey_on_member(positional1, positional2, ...)

Parameter

Comments

duplicates

string

How to handle duplicates.

Choices:

  • "overwrite"

  • "error" ← (default)

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 | ansible.builtin.rekey_on_member(key1=value1, key2=value2, ...)

Parameter

Comments

_key

string / required

The key to rekey.

Notes

Note

  • When keyword and positional parameters are used together, positional parameters must be listed before keyword parameters: input | ansible.builtin.rekey_on_member(positional1, positional2, key1=value1, key2=value2)

Examples

# mydict => {'eigrp': {'state': 'enabled', 'proto': 'eigrp'}, 'ospf': {'state': 'enabled', 'proto': 'ospf'}}
 mydict: '{{ [{"proto": "eigrp", "state": "enabled"}, {"proto": "ospf", "state": "enabled"}] | rekey_on_member("proto") }}'

Return Value

Key

Description

Return value

dictionary

The resulting dictionary.

Returned: success

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.