Skip to content

Commit c3b4b3e

Browse files
snipfoomattclay
authored andcommitted
Run all handlers with the same listen topic when notified from another handler (#82364)
Fixes #82363 (cherry picked from commit 8328153)
1 parent cfa8caf commit c3b4b3e

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bugfixes:
2+
- Run all handlers with the same ``listen`` topic, even when notified from another handler (https://github.com/ansible/ansible/issues/82363).

lib/ansible/plugins/strategy/__init__.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
from ansible.utils.display import Display
5656
from ansible.utils.fqcn import add_internal_fqcns
5757
from ansible.utils.unsafe_proxy import wrap_var
58+
from ansible.utils.sentinel import Sentinel
5859
from ansible.utils.vars import combine_vars, isidentifier
5960
from ansible.vars.clean import strip_internal_keys, module_response_deepcopy
6061

@@ -658,6 +659,7 @@ def _process_pending_results(self, iterator, one_pass=False, max_passes=None):
658659
# otherwise depending on the setting either error or warn
659660
host_state = iterator.get_state_for_host(original_host.name)
660661
for notification in result_item['_ansible_notify']:
662+
handler = Sentinel
661663
for handler in self.search_handlers_by_notification(notification, iterator):
662664
if host_state.run_state == IteratingStates.HANDLERS:
663665
# we're currently iterating handlers, so we need to expand this now
@@ -668,8 +670,8 @@ def _process_pending_results(self, iterator, one_pass=False, max_passes=None):
668670
else:
669671
iterator.add_notification(original_host.name, notification)
670672
display.vv(f"Notification for handler {notification} has been saved.")
671-
break
672-
else:
673+
break
674+
if handler is Sentinel:
673675
msg = (
674676
f"The requested handler '{notification}' was not found in either the main handlers"
675677
" list nor in the listening handlers list"

test/integration/targets/handlers/runme.sh

+3
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ done
6969
# Notify handler listen
7070
ansible-playbook test_handlers_listen.yml -i inventory.handlers -v "$@"
7171

72+
# https://github.com/ansible/ansible/issues/82363
73+
ansible-playbook test_multiple_handlers_with_recursive_notification.yml -i inventory.handlers -v "$@"
74+
7275
# Notify inexistent handlers results in error
7376
set +e
7477
result="$(ansible-playbook test_handlers_inexistent_notify.yml -i inventory.handlers "$@" 2>&1)"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
- name: test multiple handlers with recursive notification
3+
hosts: localhost
4+
gather_facts: false
5+
6+
tasks:
7+
- name: notify handler 1
8+
command: echo
9+
changed_when: true
10+
notify: handler 1
11+
12+
- meta: flush_handlers
13+
14+
- name: verify handlers
15+
assert:
16+
that:
17+
- "ran_handler_1 is defined"
18+
- "ran_handler_2a is defined"
19+
- "ran_handler_2b is defined"
20+
21+
handlers:
22+
- name: handler 1
23+
set_fact:
24+
ran_handler_1: True
25+
changed_when: true
26+
notify: handler_2
27+
28+
- name: handler 2a
29+
set_fact:
30+
ran_handler_2a: True
31+
listen: handler_2
32+
33+
- name: handler 2b
34+
set_fact:
35+
ran_handler_2b: True
36+
listen: handler_2

0 commit comments

Comments
 (0)