ansible.builtin.dict2items filter – Convert a dictionary into an itemized list of dictionaries
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
dict2items
.
However, we recommend you use the Fully Qualified Collection Name (FQCN) ansible.builtin.dict2items
for easy linking to the
plugin documentation and to avoid conflicting with other collections that may have
the same filter plugin name.
Synopsis
Takes a dictionary and transforms it into a list of dictionaries, with each having a
key
andvalue
keys that correspond to the keys and values of the original.
Input
This describes the input of the filter, the value before | ansible.builtin.dict2items
.
Parameter |
Comments |
---|---|
The dictionary to transform |
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.dict2items(positional1, positional2, ...)
Parameter |
Comments |
---|---|
The name of the property on the item representing the dictionary’s keys. Default: |
|
The name of the property on the item representing the dictionary’s values. Default: |
See Also
See also
- ansible.builtin.items2dict filter plugin
Consolidate a list of itemized dictionaries into a dictionary.
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 Value
Key |
Description |
---|---|
A list of dictionaries. Returned: success |