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 even without specifying the collections: keyword. However, we recommend you use the FQCN 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.6

Synopsis

  • Takes a dictionary and transforms it into a list of dictionaries, with each having a key and value 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

Input

dictionary / required

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

key_name

string

added in Ansible 2.8

The name of the property on the item representing the dictionary’s keys.

Default: "key"

value_name

string

added in Ansible 2.8

The name of the property on the item representing the dictionary’s values.

Default: "value"

See Also

See also

ansible.builtin.items2dict filter plugin

The official documentation on the ansible.builtin.items2dict filter plugin.

Examples

# items => [ { "key": "a", "value": 1 }, { "key": "b", "value": 2 } ]
items: "{{ {'a': 1, 'b': 2}| dict2items}}"

vars:
  files:
    users: /etc/passwd
    groups: /etc/group
  files_dicts: "{{ files | dict2items(key_name='file', value_name='path') }}"

Return Value

Key

Description

Return value

list / elements=dictionary

A list of dictionaries.

Returned: success

Authors

  • Ansible core team

Hint

Configuration entries for each entry type have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up.