community.general.counter (8.5.0) — filter

Counts hashable elements in a sequence

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

Authors: Rémy Keil (@keilr)

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

Counts hashable elements in a sequence.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Count occurrences
  ansible.builtin.debug:
    msg: >-
      {{ [1, 'a', 2, 2, 'a', 'b', 'a'] | community.general.counter }}

Inputs

    
_input:
    description: A sequence.
    elements: any
    required: true
    type: list

Outputs

_value:
  description: A dictionary with the elements of the sequence as keys, and their number
    of occurrences in the sequence as values.
  type: dictionary