community.general.counter 过滤器 – 计算序列中可哈希元素的数量
注意
此过滤器插件是 community.general 集合 (版本 10.1.0) 的一部分。
如果您正在使用 ansible 包,您可能已经安装了此集合。它不包含在 ansible-core 中。要检查是否已安装,请运行 ansible-galaxy collection list。
要安装它,请使用:ansible-galaxy collection install community.general。
要在 playbook 中使用它,请指定:community.general.counter。
community.general 4.3.0 中的新功能
概要
- 计算序列中可哈希元素的数量。 
输入
这描述了过滤器的输入,即 | community.general.counter 之前的值。
| 参数 | 注释 | 
|---|---|
| 一个序列。 | 
示例
- 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}
返回值
| 键 | 描述 | 
|---|---|
| 一个字典,其中序列的元素作为键,它们在序列中出现的次数作为值。 返回:成功 | 
