diff --git a/changelogs/fragments/last-loaded-handler-same-name-wins.yaml b/changelogs/fragments/last-loaded-handler-same-name-wins.yaml new file mode 100644 index 00000000000..4426d4775b7 --- /dev/null +++ b/changelogs/fragments/last-loaded-handler-same-name-wins.yaml @@ -0,0 +1,2 @@ +bugfixes: + - Last loaded handler with the same name is used diff --git a/lib/ansible/plugins/strategy/__init__.py b/lib/ansible/plugins/strategy/__init__.py index ceb0f8eaa97..7e5583c8201 100644 --- a/lib/ansible/plugins/strategy/__init__.py +++ b/lib/ansible/plugins/strategy/__init__.py @@ -368,7 +368,8 @@ class StrategyBase: return self._inventory.get_host(host_name) def search_handler_blocks_by_name(handler_name, handler_blocks): - for handler_block in handler_blocks: + # iterate in reversed order since last handler loaded with the same name wins + for handler_block in reversed(handler_blocks): for handler_task in handler_block.block: if handler_task.name: handler_vars = self._variable_manager.get_vars(play=iterator._play, task=handler_task) @@ -394,7 +395,8 @@ class StrategyBase: return None def search_handler_blocks_by_uuid(handler_uuid, handler_blocks): - for handler_block in handler_blocks: + # iterate in reversed order since last handler loaded with the same name wins + for handler_block in reversed(handler_blocks): for handler_task in handler_block.block: if handler_uuid == handler_task._uuid: return handler_task