community / community.general / 3.8.10 / filter / dict Convert a list of tuples into a dictionary | "added in version" 3.0.0 of community.general" Authors: Felix Fontein (@felixfontein)community.general.dict (3.8.10) — filter
Install with ansible-galaxy collection install community.general:==3.8.10
collections: - name: community.general version: 3.8.10
Convert a list of tuples into a dictionary. This is a filter version of the C(dict) function.
- name: Convert list of tuples into dictionary ansible.builtin.set_fact: dictionary: "{{ [[1, 2], ['a', 'b']] | community.general.dict }}"
# Result is {1: 2, 'a': 'b'} - name: Create a list of dictionaries with map and the community.general.dict filter ansible.builtin.debug: msg: >- {{ values | map('zip', ['k1', 'k2', 'k3']) | map('map', 'reverse') | map('community.general.dict') }} vars: values: - - foo - 23 - a - - bar - 42 - b
_input: description: A list of tuples (with exactly two elements). elements: tuple required: true type: list
_value: description: The dictionary having the provided key-value pairs. type: boolean