mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
tests: checks that handlers work with loops
This commit is contained in:
parent
a09ce4bd87
commit
aa23ea8462
4 changed files with 20 additions and 2 deletions
|
@ -51,7 +51,8 @@ test_group_by:
|
|||
ansible-playbook test_group_by.yml -i inventory.group_by -e @$(VARS_FILE) $(CREDENTIALS_ARG) -v $(TEST_FLAGS)
|
||||
|
||||
test_handlers:
|
||||
ansible-playbook test_handlers.yml -i inventory.handlers -e @$(VARS_FILE) $(CREDENTIALS_ARG) -v $(TEST_FLAGS)
|
||||
ansible-playbook test_handlers.yml --tags scenario1 -i inventory.handlers -e @$(VARS_FILE) $(CREDENTIALS_ARG) -v $(TEST_FLAGS)
|
||||
[ "$$(ansible-playbook test_handlers.yml --tags scenario2 -l A -i inventory.handlers -e @$(VARS_FILE) $(CREDENTIALS_ARG) -v $(TEST_FLAGS) | grep -Po 'RUNNING HANDLER \[test_handlers : \K[^\]]+')" = "test handler" ]
|
||||
# Not forcing, should only run on successful host
|
||||
[ "$$(ansible-playbook test_force_handlers.yml --tags normal -i inventory.handlers -e @$(VARS_FILE) $(CREDENTIALS_ARG) -v $(TEST_FLAGS) | egrep -o CALLED_HANDLER_. | sort | uniq | xargs)" = "CALLED_HANDLER_B" ]
|
||||
# Forcing from command line
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
- name: set handler fact
|
||||
set_fact:
|
||||
handler_called: True
|
||||
- name: test handler
|
||||
debug: msg="handler called"
|
||||
|
|
|
@ -20,19 +20,33 @@
|
|||
- name: reset handler_called variable to false for all hosts
|
||||
set_fact:
|
||||
handler_called: False
|
||||
tags: scenario1
|
||||
|
||||
- name: notify the handler for host A only
|
||||
shell: echo
|
||||
notify:
|
||||
- set handler fact
|
||||
when: inventory_hostname == 'A'
|
||||
tags: scenario1
|
||||
|
||||
- name: force handler execution now
|
||||
meta: "flush_handlers"
|
||||
tags: scenario1
|
||||
|
||||
- debug: var=handler_called
|
||||
tags: scenario1
|
||||
|
||||
- name: validate the handler only ran on one host
|
||||
assert:
|
||||
that:
|
||||
- "inventory_hostname == 'A' and handler_called == True or handler_called == False"
|
||||
tags: scenario1
|
||||
|
||||
- name: 'test notify with loop'
|
||||
debug: msg='a task'
|
||||
changed_when: item == 1
|
||||
notify: test handler
|
||||
with_items:
|
||||
- 1
|
||||
- 2
|
||||
tags: scenario2
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
gather_facts: False
|
||||
connection: local
|
||||
roles:
|
||||
- { role: test_handlers_meta }
|
||||
- { role: test_handlers_meta, tags: ['scenario1'] }
|
||||
|
||||
- name: verify final handler was run
|
||||
hosts: A
|
||||
|
@ -16,6 +16,7 @@
|
|||
that:
|
||||
- "not hostvars[inventory_hostname]['handler1_called']"
|
||||
- "'handler2_called' in hostvars[inventory_hostname]"
|
||||
tags: ['scenario1']
|
||||
|
||||
- name: test handlers
|
||||
hosts: testgroup
|
||||
|
|
Loading…
Reference in a new issue