Note
This filter plugin is part of the community.general collection (version 10.7.3).
You might already have this collection installed if you are using the ansible package. 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.groupby_as_dict.
New in community.general 3.1.0
groupby filter. Use the Jinja2 groupby filter if you have multiple entries with the same value, or when you need a dictionary with list values, or when you need to use deeply nested attributes.This describes the input of the filter, the value before | community.general.groupby_as_dict.
Parameter | Comments |
|---|---|
Input list / elements=dictionary / required | A list of dictionaries. |
This describes positional parameters of the filter. These are the values positional1, positional2 and so on in the following example: input | community.general.groupby_as_dict(positional1, positional2, ...)
Parameter | Comments |
|---|---|
attribute string / required | The attribute to use as the key. |
- name: Arrange a list of dictionaries as a dictionary of dictionaries
ansible.builtin.debug:
msg: "{{ sequence | community.general.groupby_as_dict('key') }}"
vars:
sequence:
- key: value
foo: bar
- key: other_value
baz: bar
# Produces the following nested structure:
#
# value:
# key: value
# foo: bar
# other_value:
# key: other_value
# baz: bar
Key | Description |
|---|---|
Return value dictionary | A dictionary containing the dictionaries from the list as values. Returned: success |
© 2012–2018 Michael DeHaan
© 2018–2025 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/latest/collections/community/general/groupby_as_dict_filter.html