Add counter filter (#3921)

* Add counter filter

* move counter filter doc to existing chapter

* Use existing typerror exception from Counter

* Match counter filter example task name and output
This commit is contained in:
Rémy Keil 2021-12-26 14:56:21 +01:00 committed by GitHub
commit 9642a15d34
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 159 additions and 0 deletions

View file

@ -0,0 +1,2 @@
shippable/posix/group2
skip/python2.6 # filters are controller only, and we no longer support Python 2.6 on the controller

View file

@ -0,0 +1,37 @@
---
####################################################################
# WARNING: These are designed specifically for Ansible tests #
# and should not be used as examples of how to write Ansible roles #
####################################################################
- name: test counter filter
assert:
that:
- "('abca' | community.general.counter) == {'a': 2, 'b': 1, 'c': 1}"
- "(['apple', 'pear', 'pear'] | community.general.counter) == {'apple': 1, 'pear': 2}"
- "([1, 2, 2, 3] | community.general.counter) == {1: 1, 2: 2, 3: 1}"
- "([1.11, 1.11, 1.12] | community.general.counter) == {1.11: 2, 1.12: 1}"
- name: test fail argument not a sequence
debug:
msg: "{{ {'a': 'b'} | community.general.counter }}"
ignore_errors: yes
register: res
- name: verify test fail argument not a sequence
assert:
that:
- res is failed
- res.msg is match('Argument for community.general.counter must be a sequence')
- name: test fail element not hashable
debug:
msg: "{{ [{'a': 'b'}] | community.general.counter }}"
ignore_errors: yes
register: res
- name: verify test fail element not hashable
assert:
that:
- res is failed
- res.msg is match('community.general.counter needs a sequence with hashable elements')