items2dict¶
Collection Note
This module is part of the ansible.builtin collection. To install the collection, use:
Added in version2.7.
Synopsis¶
- Takes a list of dicts with each having a C(key) and C(value) keys, and transforms the list into a dictionary, effectively as the reverse of R(dict2items,ansible_collections.ansible.builtin.dict2items_filter).
Parameters¶
| Parameter | Defaults / Choices | Comments |
|---|---|---|
| _input list / elements=dict required |
A list of dictionaries. Every dictionary must have keys C(key) and C(value). |
|
| key_name str |
Default: key |
The name of the key in the element dictionaries that holds the key to use at destination. |
| value_name str |
Default: value |
The name of the key in the element dictionaries that holds the value to use at destination. |
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 Values¶
| Key | Data Type | Description | Returned |
|---|---|---|---|
| _value | dict | Dictionary with the consolidated key/values. |
Authors¶
- Ansible Core Team