community.general.counter filter – Counts hashable elements in a sequence
Note
This filter plugin is part of the community.general collection (version 8.6.8).
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.counter
.
New in community.general 4.3.0
Synopsis
Counts hashable elements in a sequence.
Input
This describes the input of the filter, the value before | community.general.counter
.
Parameter |
Comments |
---|---|
A sequence. |
Examples
- name: Count occurrences
ansible.builtin.debug:
msg: >-
{{ [1, 'a', 2, 2, 'a', 'b', 'a'] | community.general.counter }}
# Produces: {1: 1, 'a': 3, 2: 2, 'b': 1}
Return Value
Key |
Description |
---|---|
A dictionary with the elements of the sequence as keys, and their number of occurrences in the sequence as values. Returned: success |