ansible.builtin.items2dict filter – Consolidate a list of itemized dictionaries into a dictionary
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
items2dict
.
However, we recommend you use the Fully Qualified Collection Name (FQCN) ansible.builtin.items2dict
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 2.7
Synopsis
Takes a list of dicts with each having a
key
andvalue
keys, and transforms the list into a dictionary, effectively as the reverse of dict2items.
Input
This describes the input of the filter, the value before | ansible.builtin.items2dict
.
Parameter |
Comments |
---|---|
A list of dictionaries. Every dictionary must have keys |
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.items2dict(positional1, positional2, ...)
Parameter |
Comments |
---|---|
The name of the key in the element dictionaries that holds the key to use at destination. Default: |
|
The name of the key in the element dictionaries that holds the value to use at destination. Default: |
See Also
See also
- ansible.builtin.dict2items filter plugin
Convert a dictionary into an itemized list of dictionaries.
Examples
# mydict => { "hi": "bye", "ciao": "ciao" }
mydict: {{ [{'key': 'hi', 'value': 'bye'}, {'key': 'ciao', 'value': 'ciao'} ]| items2dict}}
# The output is a dictionary with two key/value pairs:
# Application: payment
# Environment: dev
vars:
tags:
- key: Application
value: payment
- key: Environment
value: dev
consolidated: "{{ tags | items2dict }}"
Return Value
Key |
Description |
---|---|
Dictionary with the consolidated key/values. Returned: success |