mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge branch 'pilou--test_notify_with_loops' into devel
This commit is contained in:
commit
11be1ff2d4
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)
|
ansible-playbook test_group_by.yml -i inventory.group_by -e @$(VARS_FILE) $(CREDENTIALS_ARG) -v $(TEST_FLAGS)
|
||||||
|
|
||||||
test_handlers:
|
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
|
# 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" ]
|
[ "$$(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
|
# Forcing from command line
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
- name: set handler fact
|
- name: set handler fact
|
||||||
set_fact:
|
set_fact:
|
||||||
handler_called: True
|
handler_called: True
|
||||||
|
- name: test handler
|
||||||
|
debug: msg="handler called"
|
||||||
|
|
|
@ -20,19 +20,33 @@
|
||||||
- name: reset handler_called variable to false for all hosts
|
- name: reset handler_called variable to false for all hosts
|
||||||
set_fact:
|
set_fact:
|
||||||
handler_called: False
|
handler_called: False
|
||||||
|
tags: scenario1
|
||||||
|
|
||||||
- name: notify the handler for host A only
|
- name: notify the handler for host A only
|
||||||
shell: echo
|
shell: echo
|
||||||
notify:
|
notify:
|
||||||
- set handler fact
|
- set handler fact
|
||||||
when: inventory_hostname == 'A'
|
when: inventory_hostname == 'A'
|
||||||
|
tags: scenario1
|
||||||
|
|
||||||
- name: force handler execution now
|
- name: force handler execution now
|
||||||
meta: "flush_handlers"
|
meta: "flush_handlers"
|
||||||
|
tags: scenario1
|
||||||
|
|
||||||
- debug: var=handler_called
|
- debug: var=handler_called
|
||||||
|
tags: scenario1
|
||||||
|
|
||||||
- name: validate the handler only ran on one host
|
- name: validate the handler only ran on one host
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- "inventory_hostname == 'A' and handler_called == True or handler_called == False"
|
- "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
|
gather_facts: False
|
||||||
connection: local
|
connection: local
|
||||||
roles:
|
roles:
|
||||||
- { role: test_handlers_meta }
|
- { role: test_handlers_meta, tags: ['scenario1'] }
|
||||||
|
|
||||||
- name: verify final handler was run
|
- name: verify final handler was run
|
||||||
hosts: A
|
hosts: A
|
||||||
|
@ -16,6 +16,7 @@
|
||||||
that:
|
that:
|
||||||
- "not hostvars[inventory_hostname]['handler1_called']"
|
- "not hostvars[inventory_hostname]['handler1_called']"
|
||||||
- "'handler2_called' in hostvars[inventory_hostname]"
|
- "'handler2_called' in hostvars[inventory_hostname]"
|
||||||
|
tags: ['scenario1']
|
||||||
|
|
||||||
- name: test handlers
|
- name: test handlers
|
||||||
hosts: testgroup
|
hosts: testgroup
|
||||||
|
|
Loading…
Reference in a new issue