dict2items¶
Collection Note
This module is part of the ansible.builtin collection. To install the collection, use:
Added in version2.6.
Synopsis¶
- Takes a dictionary and transforms it into a list of dictionaries, with each having a C(key) and C(value) keys that correspond to the keys and values of the original.
Parameters¶
| Parameter | Defaults / Choices | Comments |
|---|---|---|
| _input dict required |
The dictionary to transform | |
| key_name str |
Default: key |
The name of the property on the item representing the dictionary's keys. Version Added: 2.8 |
| value_name str |
Default: value |
The name of the property on the item representing the dictionary's values. Version Added: 2.8 |
Examples¶
# items => [ { "key": "a", "value": 1 }, { "key": "b", "value": 2 } ]
items: "{{ {'a': 1, 'b': 2}| dict2items }}"
# files_dicts: [
# {
# "file": "users",
# "path": "/etc/passwd"
# },
# {
# "file": "groups",
# "path": "/etc/group"
# }
# ]
vars:
files:
users: /etc/passwd
groups: /etc/group
files_dicts: "{{ files | dict2items(key_name='file', value_name='path') }}"
Return Values¶
| Key | Data Type | Description | Returned |
|---|---|---|---|
| _value | list | A list of dictionaries. |
Authors¶
- Ansible Core Team