community.general.groupby_as_dict (8.5.0) — filter

Transform a sequence of dictionaries to a dictionary where the dictionaries are indexed by an attribute

| "added in version" 3.1.0 of community.general"

Authors: Felix Fontein (@felixfontein)

Install collection

Install with ansible-galaxy collection install community.general:==8.5.0


Add to requirements.yml

  collections:
    - name: community.general
      version: 8.5.0

Description

Transform a sequence of dictionaries to a dictionary where the dictionaries are indexed by an attribute.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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

Inputs

    
_input:
    description: A list of dictionaries
    elements: dictionary
    required: true
    type: list

attribute:
    description: The attribute to use as the key.
    required: true
    type: str

Outputs

_value:
  description: A dictionary containing the dictionaries from the list as values.
  type: dictionary