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
key and value keys, and transforms the list into a dictionary, effectively as the reverse of dict2items.This describes the input of the filter, the value before | ansible.builtin.items2dict.
Parameter | Comments |
|---|---|
Input list / elements=dictionary / required | A list of dictionaries. Every dictionary must have keys |
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 |
|---|---|
key_name string | The name of the key in the element dictionaries that holds the key to use at destination. Default: |
value_name string | The name of the key in the element dictionaries that holds the value to use at destination. Default: |
See also
Convert a dictionary into an itemized list of dictionaries.
# 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 }}"
Key | Description |
|---|---|
Return value dictionary | Dictionary with the consolidated key/values. Returned: success |
© 2012–2018 Michael DeHaan
© 2018–2025 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/latest/collections/ansible/builtin/items2dict_filter.html