From 100b20260a2c6c90fcb8a4f46e873915b6c9df7b Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Tue, 8 Jul 2025 14:42:32 -0700 Subject: [PATCH] [stable-2.19] Short-circuit legacy network module prefix->action mapping (#85406) (#85413) * Short-circuit legacy network module prefix->action mapping * Modified a non-short-circuit compound conditional in a legacy networking path that attempted to resolve an action for any module name containing `_`. The bug was always present, but the typical presentation (an ImportError) was ignored prior to 2.19. * The legacy networking path should be deprecated and removed in 2.20- a module could still be run under the wrong action if one with a matching prefix is found. * unit test fix (cherry picked from commit d6efb7db8a4cfa930f5271e82930b2b48844479c) Co-authored-by: Matt Davis <6775756+nitzmahone@users.noreply.github.com> --- lib/ansible/executor/task_executor.py | 2 +- test/units/executor/test_task_executor.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index 1809b1252f1..60c6b392cbc 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -1129,7 +1129,7 @@ class TaskExecutor: # let action plugin override module, fallback to 'normal' action plugin otherwise elif self._shared_loader_obj.action_loader.has_plugin(self._task.action, collection_list=collections): handler_name = self._task.action - elif all((module_prefix in C.NETWORK_GROUP_MODULES, self._shared_loader_obj.action_loader.has_plugin(network_action, collection_list=collections))): + elif module_prefix in C.NETWORK_GROUP_MODULES and self._shared_loader_obj.action_loader.has_plugin(network_action, collection_list=collections): handler_name = network_action display.vvvv("Using network group action {handler} for {action}".format(handler=handler_name, action=self._task.action), diff --git a/test/units/executor/test_task_executor.py b/test/units/executor/test_task_executor.py index ba919baa28f..695230b93e9 100644 --- a/test/units/executor/test_task_executor.py +++ b/test/units/executor/test_task_executor.py @@ -273,8 +273,7 @@ class TestTaskExecutor(unittest.TestCase): self.assertIs(mock.sentinel.handler, handler) - action_loader.has_plugin.assert_has_calls([mock.call(action, collection_list=te._task.collections), - mock.call(module_prefix, collection_list=te._task.collections)]) + action_loader.has_plugin.assert_has_calls([mock.call(action, collection_list=te._task.collections)]) action_loader.get.assert_called_with( 'ansible.legacy.normal', task=te._task, connection=te._connection,