summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/handlers
diff options
context:
space:
mode:
Diffstat (limited to 'test/integration/targets/handlers')
-rw-r--r--test/integration/targets/handlers/aliases3
-rw-r--r--test/integration/targets/handlers/from_handlers.yml39
-rw-r--r--test/integration/targets/handlers/handlers.yml2
-rw-r--r--test/integration/targets/handlers/inventory.handlers10
-rw-r--r--test/integration/targets/handlers/roles/test_force_handlers/handlers/main.yml2
-rw-r--r--test/integration/targets/handlers/roles/test_force_handlers/tasks/main.yml26
-rw-r--r--test/integration/targets/handlers/roles/test_handlers/handlers/main.yml5
-rw-r--r--test/integration/targets/handlers/roles/test_handlers/meta/main.yml1
-rw-r--r--test/integration/targets/handlers/roles/test_handlers/tasks/main.yml52
-rw-r--r--test/integration/targets/handlers/roles/test_handlers_include/handlers/main.yml1
-rw-r--r--test/integration/targets/handlers/roles/test_handlers_include/tasks/main.yml4
-rw-r--r--test/integration/targets/handlers/roles/test_handlers_include_role/handlers/main.yml5
-rw-r--r--test/integration/targets/handlers/roles/test_handlers_include_role/meta/main.yml1
-rw-r--r--test/integration/targets/handlers/roles/test_handlers_include_role/tasks/main.yml47
-rw-r--r--test/integration/targets/handlers/roles/test_handlers_listen/handlers/main.yml10
-rw-r--r--test/integration/targets/handlers/roles/test_handlers_listen/tasks/main.yml6
-rw-r--r--test/integration/targets/handlers/roles/test_handlers_meta/handlers/alternate.yml12
-rw-r--r--test/integration/targets/handlers/roles/test_handlers_meta/handlers/main.yml10
-rw-r--r--test/integration/targets/handlers/roles/test_handlers_meta/tasks/main.yml75
-rw-r--r--test/integration/targets/handlers/roles/test_templating_in_handlers/handlers/main.yml21
-rw-r--r--test/integration/targets/handlers/roles/test_templating_in_handlers/tasks/main.yml26
-rwxr-xr-xtest/integration/targets/handlers/runme.sh95
-rw-r--r--test/integration/targets/handlers/test_force_handlers.yml27
-rw-r--r--test/integration/targets/handlers/test_handlers.yml47
-rw-r--r--test/integration/targets/handlers/test_handlers_any_errors_fatal.yml24
-rw-r--r--test/integration/targets/handlers/test_handlers_include.yml14
-rw-r--r--test/integration/targets/handlers/test_handlers_include_role.yml8
-rw-r--r--test/integration/targets/handlers/test_handlers_including_task.yml16
-rw-r--r--test/integration/targets/handlers/test_handlers_inexistent_notify.yml10
-rw-r--r--test/integration/targets/handlers/test_handlers_listen.yml128
-rw-r--r--test/integration/targets/handlers/test_handlers_template_run_once.yml12
-rw-r--r--test/integration/targets/handlers/test_listening_handlers.yml24
-rw-r--r--test/integration/targets/handlers/test_templating_in_handlers.yml62
33 files changed, 825 insertions, 0 deletions
diff --git a/test/integration/targets/handlers/aliases b/test/integration/targets/handlers/aliases
new file mode 100644
index 00000000..30bb677a
--- /dev/null
+++ b/test/integration/targets/handlers/aliases
@@ -0,0 +1,3 @@
+shippable/posix/group5
+handlers
+skip/aix
diff --git a/test/integration/targets/handlers/from_handlers.yml b/test/integration/targets/handlers/from_handlers.yml
new file mode 100644
index 00000000..7b2dea2d
--- /dev/null
+++ b/test/integration/targets/handlers/from_handlers.yml
@@ -0,0 +1,39 @@
+- name: verify handlers_from on include_role
+ hosts: A
+ gather_facts: False
+ tags: ['scenario1']
+ tasks:
+ - name: test include_role
+ include_role: name=test_handlers_meta handlers_from=alternate.yml
+
+ - name: force handler run
+ meta: flush_handlers
+
+ - name: verify handlers ran
+ assert:
+ that:
+ - "'handler1_alt_called' in hostvars[inventory_hostname]"
+ - "'handler2_alt_called' in hostvars[inventory_hostname]"
+ tags: ['scenario1']
+
+
+- name: verify handlers_from on import_role
+ hosts: A
+ gather_facts: False
+ tasks:
+ - name: set facts to false
+ set_fact:
+ handler1_alt_called: False
+ handler2_alt_called: False
+
+ - import_role: name=test_handlers_meta handlers_from=alternate.yml
+
+ - name: force handler run
+ meta: flush_handlers
+
+ - name: verify handlers ran
+ assert:
+ that:
+ - handler1_alt_called|bool
+ - handler2_alt_called|bool
+ tags: ['scenario1']
diff --git a/test/integration/targets/handlers/handlers.yml b/test/integration/targets/handlers/handlers.yml
new file mode 100644
index 00000000..aed75bd2
--- /dev/null
+++ b/test/integration/targets/handlers/handlers.yml
@@ -0,0 +1,2 @@
+- name: test handler
+ debug: msg="handler called"
diff --git a/test/integration/targets/handlers/inventory.handlers b/test/integration/targets/handlers/inventory.handlers
new file mode 100644
index 00000000..268cf657
--- /dev/null
+++ b/test/integration/targets/handlers/inventory.handlers
@@ -0,0 +1,10 @@
+[testgroup]
+A
+B
+C
+D
+E
+
+[testgroup:vars]
+ansible_connection=local
+ansible_python_interpreter="{{ ansible_playbook_python }}"
diff --git a/test/integration/targets/handlers/roles/test_force_handlers/handlers/main.yml b/test/integration/targets/handlers/roles/test_force_handlers/handlers/main.yml
new file mode 100644
index 00000000..962d7561
--- /dev/null
+++ b/test/integration/targets/handlers/roles/test_force_handlers/handlers/main.yml
@@ -0,0 +1,2 @@
+- name: echoing handler
+ command: echo CALLED_HANDLER_{{ inventory_hostname }}
diff --git a/test/integration/targets/handlers/roles/test_force_handlers/tasks/main.yml b/test/integration/targets/handlers/roles/test_force_handlers/tasks/main.yml
new file mode 100644
index 00000000..f5d78c73
--- /dev/null
+++ b/test/integration/targets/handlers/roles/test_force_handlers/tasks/main.yml
@@ -0,0 +1,26 @@
+---
+
+# We notify for A and B, and hosts B and C fail.
+# When forcing, we expect A and B to run handlers
+# When not forcing, we expect only B to run handlers
+
+- name: notify the handler for host A and B
+ shell: echo
+ notify:
+ - echoing handler
+ when: inventory_hostname == 'A' or inventory_hostname == 'B'
+
+- name: EXPECTED FAILURE fail task for all
+ fail: msg="Fail All"
+ when: fail_all is defined and fail_all
+
+- name: EXPECTED FAILURE fail task for A
+ fail: msg="Fail A"
+ when: inventory_hostname == 'A'
+
+- name: EXPECTED FAILURE fail task for C
+ fail: msg="Fail C"
+ when: inventory_hostname == 'C'
+
+- name: echo after A and C have failed
+ command: echo CALLED_TASK_{{ inventory_hostname }}
diff --git a/test/integration/targets/handlers/roles/test_handlers/handlers/main.yml b/test/integration/targets/handlers/roles/test_handlers/handlers/main.yml
new file mode 100644
index 00000000..0261f935
--- /dev/null
+++ b/test/integration/targets/handlers/roles/test_handlers/handlers/main.yml
@@ -0,0 +1,5 @@
+- name: set handler fact
+ set_fact:
+ handler_called: True
+- name: test handler
+ debug: msg="handler called"
diff --git a/test/integration/targets/handlers/roles/test_handlers/meta/main.yml b/test/integration/targets/handlers/roles/test_handlers/meta/main.yml
new file mode 100644
index 00000000..32cf5dda
--- /dev/null
+++ b/test/integration/targets/handlers/roles/test_handlers/meta/main.yml
@@ -0,0 +1 @@
+dependencies: []
diff --git a/test/integration/targets/handlers/roles/test_handlers/tasks/main.yml b/test/integration/targets/handlers/roles/test_handlers/tasks/main.yml
new file mode 100644
index 00000000..a857dacf
--- /dev/null
+++ b/test/integration/targets/handlers/roles/test_handlers/tasks/main.yml
@@ -0,0 +1,52 @@
+# test code for the async keyword
+# (c) 2014, James Tanner <tanner.jc@gmail.com>
+
+# This file is part of Ansible
+#
+# Ansible is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Ansible is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
+
+
+- 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/targets/handlers/roles/test_handlers_include/handlers/main.yml b/test/integration/targets/handlers/roles/test_handlers_include/handlers/main.yml
new file mode 100644
index 00000000..abe01be4
--- /dev/null
+++ b/test/integration/targets/handlers/roles/test_handlers_include/handlers/main.yml
@@ -0,0 +1 @@
+- include: handlers.yml
diff --git a/test/integration/targets/handlers/roles/test_handlers_include/tasks/main.yml b/test/integration/targets/handlers/roles/test_handlers_include/tasks/main.yml
new file mode 100644
index 00000000..84f0a583
--- /dev/null
+++ b/test/integration/targets/handlers/roles/test_handlers_include/tasks/main.yml
@@ -0,0 +1,4 @@
+- name: 'main task'
+ debug: msg='main task'
+ changed_when: True
+ notify: test handler
diff --git a/test/integration/targets/handlers/roles/test_handlers_include_role/handlers/main.yml b/test/integration/targets/handlers/roles/test_handlers_include_role/handlers/main.yml
new file mode 100644
index 00000000..0261f935
--- /dev/null
+++ b/test/integration/targets/handlers/roles/test_handlers_include_role/handlers/main.yml
@@ -0,0 +1,5 @@
+- name: set handler fact
+ set_fact:
+ handler_called: True
+- name: test handler
+ debug: msg="handler called"
diff --git a/test/integration/targets/handlers/roles/test_handlers_include_role/meta/main.yml b/test/integration/targets/handlers/roles/test_handlers_include_role/meta/main.yml
new file mode 100644
index 00000000..32cf5dda
--- /dev/null
+++ b/test/integration/targets/handlers/roles/test_handlers_include_role/meta/main.yml
@@ -0,0 +1 @@
+dependencies: []
diff --git a/test/integration/targets/handlers/roles/test_handlers_include_role/tasks/main.yml b/test/integration/targets/handlers/roles/test_handlers_include_role/tasks/main.yml
new file mode 100644
index 00000000..fbc3d1c5
--- /dev/null
+++ b/test/integration/targets/handlers/roles/test_handlers_include_role/tasks/main.yml
@@ -0,0 +1,47 @@
+# This file is part of Ansible
+#
+# Ansible is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Ansible is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
+
+
+- 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
+
+# item below is passed in by the playbook that calls this
+- name: 'test notify with loop'
+ debug: msg='a task'
+ changed_when: item == 1
+ notify: test handler
+ tags: scenario2
diff --git a/test/integration/targets/handlers/roles/test_handlers_listen/handlers/main.yml b/test/integration/targets/handlers/roles/test_handlers_listen/handlers/main.yml
new file mode 100644
index 00000000..3bfd82a2
--- /dev/null
+++ b/test/integration/targets/handlers/roles/test_handlers_listen/handlers/main.yml
@@ -0,0 +1,10 @@
+---
+- name: notify_listen_ran_4_3
+ set_fact:
+ notify_listen_ran_4_3: True
+ listen: notify_listen
+
+- name: notify_listen_in_role_4
+ set_fact:
+ notify_listen_in_role_4: True
+ listen: notify_listen_in_role
diff --git a/test/integration/targets/handlers/roles/test_handlers_listen/tasks/main.yml b/test/integration/targets/handlers/roles/test_handlers_listen/tasks/main.yml
new file mode 100644
index 00000000..bac9b71e
--- /dev/null
+++ b/test/integration/targets/handlers/roles/test_handlers_listen/tasks/main.yml
@@ -0,0 +1,6 @@
+---
+- name: notify some handlers from a role
+ command: uptime
+ notify:
+ - notify_listen_from_role
+ - notify_listen_in_role
diff --git a/test/integration/targets/handlers/roles/test_handlers_meta/handlers/alternate.yml b/test/integration/targets/handlers/roles/test_handlers_meta/handlers/alternate.yml
new file mode 100644
index 00000000..9268ce51
--- /dev/null
+++ b/test/integration/targets/handlers/roles/test_handlers_meta/handlers/alternate.yml
@@ -0,0 +1,12 @@
+- name: set_handler_fact_1
+ set_fact:
+ handler1_called: True
+ handler1_alt_called: True
+
+- name: set_handler_fact_2
+ set_fact:
+ handler2_called: True
+ handler2_alt_called: True
+
+- name: count_handler
+ shell: echo . >> {{ handler_countpath }}
diff --git a/test/integration/targets/handlers/roles/test_handlers_meta/handlers/main.yml b/test/integration/targets/handlers/roles/test_handlers_meta/handlers/main.yml
new file mode 100644
index 00000000..0dd408b7
--- /dev/null
+++ b/test/integration/targets/handlers/roles/test_handlers_meta/handlers/main.yml
@@ -0,0 +1,10 @@
+- name: set_handler_fact_1
+ set_fact:
+ handler1_called: True
+
+- name: set_handler_fact_2
+ set_fact:
+ handler2_called: True
+
+- name: count_handler
+ shell: echo . >> {{ handler_countpath }}
diff --git a/test/integration/targets/handlers/roles/test_handlers_meta/tasks/main.yml b/test/integration/targets/handlers/roles/test_handlers_meta/tasks/main.yml
new file mode 100644
index 00000000..d9f5c574
--- /dev/null
+++ b/test/integration/targets/handlers/roles/test_handlers_meta/tasks/main.yml
@@ -0,0 +1,75 @@
+# test code for the async keyword
+# (c) 2014, James Tanner <tanner.jc@gmail.com>
+
+# This file is part of Ansible
+#
+# Ansible is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Ansible is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
+
+- name: notify the first handler
+ shell: echo
+ notify:
+ - set_handler_fact_1
+
+- name: force handler execution now
+ meta: "flush_handlers"
+
+- name: assert handler1 ran and not handler2
+ assert:
+ that:
+ - "handler1_called is defined"
+ - "handler2_called is not defined"
+
+- name: make a tempfile for counting
+ shell: mktemp
+ register: mktemp_out
+
+- name: register tempfile path
+ set_fact:
+ handler_countpath: "{{ mktemp_out.stdout }}"
+
+- name: notify the counting handler
+ shell: echo
+ notify:
+ - count_handler
+
+- name: notify the counting handler again
+ shell: echo
+ notify:
+ - count_handler
+
+- name: force handler execution now
+ meta: flush_handlers
+
+- name: get handler execution count
+ shell: cat {{ handler_countpath }} | grep -o . | wc -l
+ register: exec_count_out
+
+- debug: var=exec_count_out.stdout
+
+- name: ensure single execution
+ assert:
+ that:
+ - exec_count_out.stdout | int == 1
+
+- name: cleanup tempfile
+ file: path={{ handler_countpath }} state=absent
+
+- name: reset handler1_called
+ set_fact:
+ handler1_called: False
+
+- name: notify the second handler
+ shell: echo
+ notify:
+ - set_handler_fact_2
diff --git a/test/integration/targets/handlers/roles/test_templating_in_handlers/handlers/main.yml b/test/integration/targets/handlers/roles/test_templating_in_handlers/handlers/main.yml
new file mode 100644
index 00000000..7dbf3347
--- /dev/null
+++ b/test/integration/targets/handlers/roles/test_templating_in_handlers/handlers/main.yml
@@ -0,0 +1,21 @@
+---
+- name: name1
+ set_fact:
+ role_non_templated_name: True
+- name: "{{ handler2 }}"
+ set_fact:
+ role_templated_name: True
+- name: testlistener1
+ set_fact:
+ role_non_templated_listener: True
+ listen: name3
+- name: testlistener2
+ set_fact:
+ role_templated_listener: True
+ listen: "{{ handler4 }}"
+- name: name5
+ set_fact:
+ role_handler5: True
+- set_fact:
+ role_handler6: True
+ listen: name6
diff --git a/test/integration/targets/handlers/roles/test_templating_in_handlers/tasks/main.yml b/test/integration/targets/handlers/roles/test_templating_in_handlers/tasks/main.yml
new file mode 100644
index 00000000..54174172
--- /dev/null
+++ b/test/integration/targets/handlers/roles/test_templating_in_handlers/tasks/main.yml
@@ -0,0 +1,26 @@
+---
+- command: echo Hello World
+ notify:
+ - "{{ handler1 }}"
+ - "{{ handler2 }}"
+ - "{{ handler3 }}"
+ - "{{ handler4 }}"
+
+- meta: flush_handlers
+
+- assert:
+ that:
+ - role_non_templated_name is defined
+ - role_templated_name is defined
+ - role_non_templated_listener is defined
+ - role_templated_listener is undefined
+
+- command: echo
+ notify: "{{ handler_list }}"
+
+- meta: flush_handlers
+
+- assert:
+ that:
+ - role_handler5 is defined
+ - role_handler6 is defined
diff --git a/test/integration/targets/handlers/runme.sh b/test/integration/targets/handlers/runme.sh
new file mode 100755
index 00000000..59c81bce
--- /dev/null
+++ b/test/integration/targets/handlers/runme.sh
@@ -0,0 +1,95 @@
+#!/usr/bin/env bash
+
+set -eux
+
+export ANSIBLE_FORCE_HANDLERS
+
+ANSIBLE_FORCE_HANDLERS=false
+
+# simple handler test
+ansible-playbook test_handlers.yml -i inventory.handlers -v "$@" --tags scenario1
+
+# simple from_handlers test
+ansible-playbook from_handlers.yml -i inventory.handlers -v "$@" --tags scenario1
+
+ansible-playbook test_listening_handlers.yml -i inventory.handlers -v "$@"
+
+[ "$(ansible-playbook test_handlers.yml -i inventory.handlers -v "$@" --tags scenario2 -l A \
+| grep -E -o 'RUNNING HANDLER \[test_handlers : .*?]')" = "RUNNING HANDLER [test_handlers : test handler]" ]
+
+# Test forcing handlers using the linear and free strategy
+for strategy in linear free; do
+
+ export ANSIBLE_STRATEGY=$strategy
+
+ # Not forcing, should only run on successful host
+ [ "$(ansible-playbook test_force_handlers.yml -i inventory.handlers -v "$@" --tags normal \
+ | grep -E -o CALLED_HANDLER_. | sort | uniq | xargs)" = "CALLED_HANDLER_B" ]
+
+ # Forcing from command line
+ [ "$(ansible-playbook test_force_handlers.yml -i inventory.handlers -v "$@" --tags normal --force-handlers \
+ | grep -E -o CALLED_HANDLER_. | sort | uniq | xargs)" = "CALLED_HANDLER_A CALLED_HANDLER_B" ]
+
+ # Forcing from command line, should only run later tasks on unfailed hosts
+ [ "$(ansible-playbook test_force_handlers.yml -i inventory.handlers -v "$@" --tags normal --force-handlers \
+ | grep -E -o CALLED_TASK_. | sort | uniq | xargs)" = "CALLED_TASK_B CALLED_TASK_D CALLED_TASK_E" ]
+
+ # Forcing from command line, should call handlers even if all hosts fail
+ [ "$(ansible-playbook test_force_handlers.yml -i inventory.handlers -v "$@" --tags normal --force-handlers -e fail_all=yes \
+ | grep -E -o CALLED_HANDLER_. | sort | uniq | xargs)" = "CALLED_HANDLER_A CALLED_HANDLER_B" ]
+
+ # Forcing from ansible.cfg
+ [ "$(ANSIBLE_FORCE_HANDLERS=true ansible-playbook test_force_handlers.yml -i inventory.handlers -v "$@" --tags normal \
+ | grep -E -o CALLED_HANDLER_. | sort | uniq | xargs)" = "CALLED_HANDLER_A CALLED_HANDLER_B" ]
+
+ # Forcing true in play
+ [ "$(ansible-playbook test_force_handlers.yml -i inventory.handlers -v "$@" --tags force_true_in_play \
+ | grep -E -o CALLED_HANDLER_. | sort | uniq | xargs)" = "CALLED_HANDLER_A CALLED_HANDLER_B" ]
+
+ # Forcing false in play, which overrides command line
+ [ "$(ansible-playbook test_force_handlers.yml -i inventory.handlers -v "$@" --tags force_false_in_play --force-handlers \
+ | grep -E -o CALLED_HANDLER_. | sort | uniq | xargs)" = "CALLED_HANDLER_B" ]
+
+ unset ANSIBLE_STRATEGY
+
+done
+
+[ "$(ansible-playbook test_handlers_include.yml -i ../../inventory -v "$@" --tags playbook_include_handlers \
+| grep -E -o 'RUNNING HANDLER \[.*?]')" = "RUNNING HANDLER [test handler]" ]
+
+[ "$(ansible-playbook test_handlers_include.yml -i ../../inventory -v "$@" --tags role_include_handlers \
+| grep -E -o 'RUNNING HANDLER \[test_handlers_include : .*?]')" = "RUNNING HANDLER [test_handlers_include : test handler]" ]
+
+[ "$(ansible-playbook test_handlers_include_role.yml -i ../../inventory -v "$@" \
+| grep -E -o 'RUNNING HANDLER \[test_handlers_include_role : .*?]')" = "RUNNING HANDLER [test_handlers_include_role : test handler]" ]
+
+# Notify handler listen
+ansible-playbook test_handlers_listen.yml -i inventory.handlers -v "$@"
+
+# Notify inexistent handlers results in error
+set +e
+result="$(ansible-playbook test_handlers_inexistent_notify.yml -i inventory.handlers "$@" 2>&1)"
+set -e
+grep -q "ERROR! The requested handler 'notify_inexistent_handler' was not found in either the main handlers list nor in the listening handlers list" <<< "$result"
+
+# Notify inexistent handlers without errors when ANSIBLE_ERROR_ON_MISSING_HANDLER=false
+ANSIBLE_ERROR_ON_MISSING_HANDLER=false ansible-playbook test_handlers_inexistent_notify.yml -i inventory.handlers -v "$@"
+
+ANSIBLE_ERROR_ON_MISSING_HANDLER=false ansible-playbook test_templating_in_handlers.yml -v "$@"
+
+# https://github.com/ansible/ansible/issues/36649
+output_dir=/tmp
+set +e
+result="$(ansible-playbook test_handlers_any_errors_fatal.yml -e output_dir=$output_dir -i inventory.handlers -v "$@" 2>&1)"
+set -e
+[ ! -f $output_dir/should_not_exist_B ] || (rm -f $output_dir/should_not_exist_B && exit 1)
+
+# https://github.com/ansible/ansible/issues/47287
+[ "$(ansible-playbook test_handlers_including_task.yml -i ../../inventory -v "$@" | grep -E -o 'failed=[0-9]+')" = "failed=0" ]
+
+# https://github.com/ansible/ansible/issues/27237
+set +e
+result="$(ansible-playbook test_handlers_template_run_once.yml -i inventory.handlers "$@" 2>&1)"
+set -e
+grep -q "handler A" <<< "$result"
+grep -q "handler B" <<< "$result"
diff --git a/test/integration/targets/handlers/test_force_handlers.yml b/test/integration/targets/handlers/test_force_handlers.yml
new file mode 100644
index 00000000..9cff7729
--- /dev/null
+++ b/test/integration/targets/handlers/test_force_handlers.yml
@@ -0,0 +1,27 @@
+---
+
+- name: test force handlers (default)
+ tags: normal
+ hosts: testgroup
+ gather_facts: False
+ roles:
+ - { role: test_force_handlers }
+ tasks:
+ - debug: msg="you should see this with --tags=normal"
+
+- name: test force handlers (set to true)
+ tags: force_true_in_play
+ hosts: testgroup
+ gather_facts: False
+ force_handlers: True
+ roles:
+ - { role: test_force_handlers, tags: force_true_in_play }
+
+
+- name: test force handlers (set to false)
+ tags: force_false_in_play
+ hosts: testgroup
+ gather_facts: False
+ force_handlers: False
+ roles:
+ - { role: test_force_handlers, tags: force_false_in_play }
diff --git a/test/integration/targets/handlers/test_handlers.yml b/test/integration/targets/handlers/test_handlers.yml
new file mode 100644
index 00000000..ae9847ba
--- /dev/null
+++ b/test/integration/targets/handlers/test_handlers.yml
@@ -0,0 +1,47 @@
+---
+- name: run handlers
+ hosts: A
+ gather_facts: False
+ roles:
+ - { role: test_handlers_meta, tags: ['scenario1'] }
+
+- name: verify final handler was run
+ hosts: A
+ gather_facts: False
+ tasks:
+ - name: verify handler2 ran
+ assert:
+ that:
+ - "not hostvars[inventory_hostname]['handler1_called']"
+ - "'handler2_called' in hostvars[inventory_hostname]"
+ tags: ['scenario1']
+
+- name: verify listening handlers
+ hosts: A
+ gather_facts: False
+ tasks:
+ - name: notify some handlers
+ command: echo foo
+ notify:
+ - notify_listen
+ post_tasks:
+ - name: assert all defined handlers ran without error
+ assert:
+ that:
+ - "notify_listen_ran_1 is defined"
+ - "notify_listen_ran_2 is defined"
+ handlers:
+ - name: first listening handler has a name
+ set_fact:
+ notify_listen_ran_1: True
+ listen: notify_listen
+ # second listening handler does not
+ - set_fact:
+ notify_listen_ran_2: True
+ listen: notify_listen
+
+- name: test handlers
+ hosts: testgroup
+ gather_facts: False
+ roles:
+ - { role: test_handlers }
diff --git a/test/integration/targets/handlers/test_handlers_any_errors_fatal.yml b/test/integration/targets/handlers/test_handlers_any_errors_fatal.yml
new file mode 100644
index 00000000..6b791a3b
--- /dev/null
+++ b/test/integration/targets/handlers/test_handlers_any_errors_fatal.yml
@@ -0,0 +1,24 @@
+- hosts:
+ - A
+ - B
+ gather_facts: no
+ any_errors_fatal: yes
+ vars:
+ output_dir: /tmp
+ tasks:
+ - name: Task one
+ debug:
+ msg: 'task 1'
+ changed_when: yes
+ notify: EXPECTED FAILURE failed_handler
+
+ - meta: flush_handlers
+
+ - name: This task should never happen
+ file:
+ path: "{{ output_dir }}/should_not_exist_{{ inventory_hostname }}"
+ state: touch
+ handlers:
+ - name: EXPECTED FAILURE failed_handler
+ fail:
+ when: 'inventory_hostname == "A"'
diff --git a/test/integration/targets/handlers/test_handlers_include.yml b/test/integration/targets/handlers/test_handlers_include.yml
new file mode 100644
index 00000000..5514fc10
--- /dev/null
+++ b/test/integration/targets/handlers/test_handlers_include.yml
@@ -0,0 +1,14 @@
+- name: verify that play can include handler
+ hosts: testhost
+ tasks:
+ - debug: msg="main task"
+ changed_when: True
+ notify: test handler
+ tags: ['playbook_include_handlers']
+ handlers:
+ - include: handlers.yml
+
+- name: verify that role can include handler
+ hosts: testhost
+ roles:
+ - { role: test_handlers_include, tags: ['role_include_handlers'] }
diff --git a/test/integration/targets/handlers/test_handlers_include_role.yml b/test/integration/targets/handlers/test_handlers_include_role.yml
new file mode 100644
index 00000000..77e6b53a
--- /dev/null
+++ b/test/integration/targets/handlers/test_handlers_include_role.yml
@@ -0,0 +1,8 @@
+- name: verify that play can include handler
+ hosts: testhost
+ tasks:
+ - include_role:
+ name: test_handlers_include_role
+ with_items:
+ - 1
+ - 2
diff --git a/test/integration/targets/handlers/test_handlers_including_task.yml b/test/integration/targets/handlers/test_handlers_including_task.yml
new file mode 100644
index 00000000..8f7933ab
--- /dev/null
+++ b/test/integration/targets/handlers/test_handlers_including_task.yml
@@ -0,0 +1,16 @@
+---
+- name: Verify handler can include other tasks (#47287)
+ hosts: testhost
+ tasks:
+ - name: include a task from the tasks section
+ include_tasks: handlers.yml
+
+ - name: notify a handler
+ debug:
+ msg: notifying handler
+ changed_when: yes
+ notify: include a task from the handlers section
+
+ handlers:
+ - name: include a task from the handlers section
+ include_tasks: handlers.yml
diff --git a/test/integration/targets/handlers/test_handlers_inexistent_notify.yml b/test/integration/targets/handlers/test_handlers_inexistent_notify.yml
new file mode 100644
index 00000000..15de38aa
--- /dev/null
+++ b/test/integration/targets/handlers/test_handlers_inexistent_notify.yml
@@ -0,0 +1,10 @@
+---
+- name: notify inexistent handler
+ hosts: localhost
+ gather_facts: false
+ tasks:
+ - name: test notify an inexistent handler
+ command: uptime
+ notify:
+ - notify_inexistent_handler
+ register: result
diff --git a/test/integration/targets/handlers/test_handlers_listen.yml b/test/integration/targets/handlers/test_handlers_listen.yml
new file mode 100644
index 00000000..dd2cd87d
--- /dev/null
+++ b/test/integration/targets/handlers/test_handlers_listen.yml
@@ -0,0 +1,128 @@
+---
+- name: test listen with named handlers
+ hosts: localhost
+ gather_facts: false
+ tasks:
+ - name: test notify handlers listen
+ command: uptime
+ notify:
+ - notify_listen
+ - meta: flush_handlers
+ - name: verify test notify handlers listen
+ assert:
+ that:
+ - "notify_listen_ran_1_1 is defined"
+ - "notify_listen_ran_1_2 is defined"
+ - "notify_listen_ran_1_3 is undefined"
+ handlers:
+ - name: notify_handler_ran_1_1
+ set_fact:
+ notify_listen_ran_1_1: True
+ listen: notify_listen
+ - name: notify_handler_ran_1_2
+ set_fact:
+ notify_listen_ran_1_2: True
+ listen: notify_listen
+ - name: notify_handler_ran_1_3
+ set_fact:
+ notify_handler_ran_1_3: True
+ listen: notify_listen2
+
+- name: test listen unnamed handlers
+ hosts: localhost
+ gather_facts: false
+ pre_tasks:
+ - name: notify some handlers
+ command: echo foo
+ notify:
+ - notify_listen
+ tasks:
+ - meta: flush_handlers
+ - name: assert all defined handlers ran without error
+ assert:
+ that:
+ - "notify_listen_ran_1 is defined"
+ - "notify_listen_ran_2 is defined"
+ - "notify_listen_ran_3 is undefined"
+ handlers:
+ - set_fact:
+ notify_listen_ran_1: True
+ listen: notify_listen
+ - set_fact:
+ notify_listen_ran_2: True
+ listen: notify_listen
+ - set_fact:
+ notify_handler_ran_3: True
+ listen: notify_listen2
+
+- name: test with mixed notify by name and listen
+ hosts: localhost
+ gather_facts: false
+ tasks:
+ - name: test notify handlers names and identical listen
+ command: uptime
+ notify:
+ - notify_listen
+ - meta: flush_handlers
+ - name: verify test notify handlers names and identical listen
+ assert:
+ that:
+ - "notify_handler_name_ran_3 is defined"
+ - "notify_handler_name_ran_3_1 is not defined"
+ - "notify_listen_ran_3_2 is defined"
+ - "notify_listen_ran_3_3 is defined"
+ - "not_notify_listen_3_4 is not defined"
+ handlers:
+ - name: notify_listen
+ set_fact:
+ notify_handler_name_ran_3: True
+ # this will not run as we have a handler with a identical name notified first
+ - name: notify_listen
+ set_fact:
+ notify_handler_name_ran_3_1: True
+ - name: notify_handler_ran_3_2
+ set_fact:
+ notify_listen_ran_3_2: True
+ listen: notify_listen
+ - name: notify_handler_ran_3_3
+ set_fact:
+ notify_listen_ran_3_3: True
+ listen: notify_listen
+ # this one is not notified
+ - name: not_notify_listen_3_4
+ set_fact:
+ not_notify_listen_3_4: True
+ listen: not_notified
+
+- name: test listen in roles
+ hosts: localhost
+ gather_facts: false
+ roles:
+ - role: test_handlers_listen
+ tasks:
+ - name: test notify handlers listen in roles
+ command: uptime
+ notify:
+ - notify_listen
+ - meta: flush_handlers
+ - name: verify test notify handlers listen in roles
+ assert:
+ that:
+ - "notify_listen_ran_4_1 is defined"
+ - "notify_listen_ran_4_2 is defined"
+ - "notify_listen_ran_4_3 is defined"
+ - "notify_listen_in_role_4 is defined"
+ - "notify_listen_from_role_4 is defined"
+ handlers:
+ - name: notify_listen_ran_4_1
+ set_fact:
+ notify_listen_ran_4_1: True
+ listen: notify_listen
+ - name: notify_listen_ran_4_2
+ set_fact:
+ notify_listen_ran_4_2: True
+ listen: notify_listen
+ - name: notify_listen_from_role_4
+ set_fact:
+ notify_listen_from_role_4: True
+ listen: notify_listen_from_role
diff --git a/test/integration/targets/handlers/test_handlers_template_run_once.yml b/test/integration/targets/handlers/test_handlers_template_run_once.yml
new file mode 100644
index 00000000..6edc32e2
--- /dev/null
+++ b/test/integration/targets/handlers/test_handlers_template_run_once.yml
@@ -0,0 +1,12 @@
+- hosts: A,B
+ gather_facts: no
+ tasks:
+ - debug:
+ changed_when: true
+ notify:
+ - handler
+ handlers:
+ - name: handler
+ debug:
+ msg: "handler {{ inventory_hostname }}"
+ run_once: "{{ testvar | default(False) }}"
diff --git a/test/integration/targets/handlers/test_listening_handlers.yml b/test/integration/targets/handlers/test_listening_handlers.yml
new file mode 100644
index 00000000..67bdad9a
--- /dev/null
+++ b/test/integration/targets/handlers/test_listening_handlers.yml
@@ -0,0 +1,24 @@
+---
+- name: verify listening handlers
+ hosts: A
+ gather_facts: False
+ tasks:
+ - name: notify some handlers
+ command: echo foo
+ notify:
+ - notify_listen
+ post_tasks:
+ - name: assert all defined handlers ran without error
+ assert:
+ that:
+ - "notify_listen_ran_1 is defined"
+ - "notify_listen_ran_2 is defined"
+ handlers:
+ - name: first listening handler has a name
+ set_fact:
+ notify_listen_ran_1: True
+ listen: notify_listen
+ # second listening handler does not
+ - set_fact:
+ notify_listen_ran_2: True
+ listen: notify_listen
diff --git a/test/integration/targets/handlers/test_templating_in_handlers.yml b/test/integration/targets/handlers/test_templating_in_handlers.yml
new file mode 100644
index 00000000..662b8c1e
--- /dev/null
+++ b/test/integration/targets/handlers/test_templating_in_handlers.yml
@@ -0,0 +1,62 @@
+- name: test templated values in handlers
+ hosts: localhost
+ gather_facts: no
+ vars:
+ handler1: name1
+ handler2: name2
+ handler3: name3
+ handler4: name4
+ handler_list:
+ - name5
+ - name6
+
+ handlers:
+ - name: name1
+ set_fact:
+ non_templated_name: True
+ - name: "{{ handler2 }}"
+ set_fact:
+ templated_name: True
+ - name: testlistener1
+ set_fact:
+ non_templated_listener: True
+ listen: name3
+ - name: testlistener2
+ set_fact:
+ templated_listener: True
+ listen: "{{ handler4 }}"
+ - name: name5
+ set_fact:
+ handler5: True
+ - set_fact:
+ handler6: True
+ listen: name6
+
+ tasks:
+ - command: echo Hello World
+ notify:
+ - "{{ handler1 }}"
+ - "{{ handler2 }}"
+ - "{{ handler3 }}"
+ - "{{ handler4 }}"
+
+ - meta: flush_handlers
+
+ - assert:
+ that:
+ - non_templated_name is defined
+ - templated_name is defined
+ - non_templated_listener is defined
+ - templated_listener is undefined
+
+ - command: echo
+ notify: "{{ handler_list }}"
+
+ - meta: flush_handlers
+
+ - assert:
+ that:
+ - handler5 is defined
+ - handler6 is defined
+
+ - include_role: name=test_templating_in_handlers