diff --git a/test/integration/Makefile b/test/integration/Makefile index 3d4555b54f1..ec790ae7093 100644 --- a/test/integration/Makefile +++ b/test/integration/Makefile @@ -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 diff --git a/test/integration/roles/test_handlers/handlers/main.yml b/test/integration/roles/test_handlers/handlers/main.yml index 117741f825d..b8ee48b5c88 100644 --- a/test/integration/roles/test_handlers/handlers/main.yml +++ b/test/integration/roles/test_handlers/handlers/main.yml @@ -1,3 +1,5 @@ - name: set handler fact set_fact: handler_called: True +- name: test handler + debug: msg="handler called" diff --git a/test/integration/roles/test_handlers/tasks/main.yml b/test/integration/roles/test_handlers/tasks/main.yml index 6f117681883..1c1d819269a 100644 --- a/test/integration/roles/test_handlers/tasks/main.yml +++ b/test/integration/roles/test_handlers/tasks/main.yml @@ -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 diff --git a/test/integration/test_handlers.yml b/test/integration/test_handlers.yml index 6a5366408c7..dafa9ceebe6 100644 --- a/test/integration/test_handlers.yml +++ b/test/integration/test_handlers.yml @@ -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