Skip to content

Commit 8328153

Browse files
authored
Run all handlers with the same listen topic when notified from another handler (#82364)
Fixes #82363
1 parent fe81164 commit 8328153

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
@@ -53,6 +53,7 @@
5353
from ansible.utils.display import Display
5454
from ansible.utils.fqcn import add_internal_fqcns
5555
from ansible.utils.unsafe_proxy import wrap_var
56+
from ansible.utils.sentinel import Sentinel
5657
from ansible.utils.vars import combine_vars, isidentifier
5758
from ansible.vars.clean import strip_internal_keys, module_response_deepcopy
5859

@@ -656,6 +657,7 @@ def _process_pending_results(self, iterator, one_pass=False, max_passes=None):
656657
# otherwise depending on the setting either error or warn
657658
host_state = iterator.get_state_for_host(original_host.name)
658659
for notification in result_item['_ansible_notify']:
660+
handler = Sentinel
659661
for handler in self.search_handlers_by_notification(notification, iterator):
660662
if host_state.run_state == IteratingStates.HANDLERS:
661663
# we're currently iterating handlers, so we need to expand this now
@@ -666,8 +668,8 @@ def _process_pending_results(self, iterator, one_pass=False, max_passes=None):
666668
else:
667669
iterator.add_notification(original_host.name, notification)
668670
display.vv(f"Notification for handler {notification} has been saved.")
669-
break
670-
else:
671+
break
672+
if handler is Sentinel:
671673
msg = (
672674
f"The requested handler '{notification}' was not found in either the main handlers"
673675
" 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)