mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Alternately track listening handlers by uuid if no name is set
Fixes #17846
This commit is contained in:
parent
527d8307c1
commit
4f06a86161
5 changed files with 85 additions and 19 deletions
|
@ -147,7 +147,14 @@ class TaskQueueManager:
|
|||
for listener in listeners:
|
||||
if listener not in self._listening_handlers:
|
||||
self._listening_handlers[listener] = []
|
||||
|
||||
# if the handler has a name, we append it to the list of listening
|
||||
# handlers, otherwise we use the uuid to avoid trampling on other
|
||||
# nameless listeners
|
||||
if handler.name:
|
||||
self._listening_handlers[listener].append(handler.get_name())
|
||||
else:
|
||||
self._listening_handlers[listener].append(handler._uuid)
|
||||
|
||||
def load_callbacks(self):
|
||||
'''
|
||||
|
|
|
@ -241,6 +241,7 @@ class StrategyBase:
|
|||
def search_handler_blocks(handler_name, handler_blocks):
|
||||
for handler_block in handler_blocks:
|
||||
for handler_task in handler_block.block:
|
||||
if handler_task.name:
|
||||
handler_vars = self._variable_manager.get_vars(loader=self._loader, play=iterator._play, task=handler_task)
|
||||
templar = Templar(loader=self._loader, variables=handler_vars)
|
||||
try:
|
||||
|
@ -261,6 +262,11 @@ class StrategyBase:
|
|||
# set_fact or some other method, and we don't want to error
|
||||
# out unnecessarily
|
||||
continue
|
||||
else:
|
||||
# if the handler name is not set, we check via the handlers uuid.
|
||||
# this is mainly used by listening handlers only
|
||||
if handler_name == handler_task._uuid:
|
||||
return handler_task
|
||||
return None
|
||||
|
||||
def parent_handler_match(target_handler, handler_name):
|
||||
|
@ -415,6 +421,8 @@ class StrategyBase:
|
|||
listening_handler = search_handler_blocks(listening_handler_name, iterator._play.handlers)
|
||||
if listening_handler is not None:
|
||||
found = True
|
||||
else:
|
||||
continue
|
||||
if original_host not in self._notified_handlers[listening_handler]:
|
||||
self._notified_handlers[listening_handler].append(original_host)
|
||||
display.vv("NOTIFIED HANDLER %s" % (listening_handler_name,))
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
set -eux
|
||||
|
||||
ansible-playbook test_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 \
|
||||
| egrep -o 'RUNNING HANDLER \[test_handlers : .*?]')" = "RUNNING HANDLER [test_handlers : test handler]" ]
|
||||
|
|
|
@ -18,6 +18,31 @@
|
|||
- "'handler2_called' in hostvars[inventory_hostname]"
|
||||
tags: ['scenario1']
|
||||
|
||||
- name: verify listening handlers
|
||||
hosts: A
|
||||
gather_facts: False
|
||||
connection: local
|
||||
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
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
---
|
||||
- name: verify listening handlers
|
||||
hosts: A
|
||||
gather_facts: False
|
||||
connection: local
|
||||
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
|
Loading…
Reference in a new issue