community.general.dict_kv filter – Convert a value to a dictionary with a single key-value pair

Note

This filter plugin is part of the community.general collection (version 6.6.9).

It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.general.

To use it in a playbook, specify: community.general.dict_kv.

New in community.general 1.3.0

Synopsis

  • Convert a value to a dictionary with a single key-value pair.

Input

This describes the input of the filter, the value before | community.general.dict_kv.

Parameter

Comments

Input

any / required

The value for the single key-value pair.

Positional parameters

This describes positional parameters of the filter. These are the values positional1, positional2 and so on in the following example: input | community.general.dict_kv(positional1, positional2, ...)

Parameter

Comments

key

any / required

The key for the single key-value pair.

Examples

- name: Create a one-element dictionary from a value
  ansible.builtin.debug:
    msg: "{{ 'myvalue' | dict_kv('mykey') }}"
    # Produces the dictionary {'mykey': 'myvalue'}

Return Value

Key

Description

Return value

dictionary

A dictionary with a single key-value pair.

Returned: success

Authors

  • Stanislav German-Evtushenko (@giner)

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.