diff --git a/changelogs/fragments/forced_local+fix+.yml b/changelogs/fragments/forced_local+fix+.yml new file mode 100644 index 00000000000..4186453bfb5 --- /dev/null +++ b/changelogs/fragments/forced_local+fix+.yml @@ -0,0 +1,2 @@ +bugfixes: + - core will now also look at the connection plugin to force 'local' interpreter for networking path compatibility as just ansible_network_os could be misleading. diff --git a/lib/ansible/executor/task_executor.py b/lib/ansible/executor/task_executor.py index 784f80a5a1c..47141f06984 100644 --- a/lib/ansible/executor/task_executor.py +++ b/lib/ansible/executor/task_executor.py @@ -595,9 +595,9 @@ class TaskExecutor: # feed back into pc to ensure plugins not using get_option can get correct value self._connection._play_context = self._play_context.set_task_and_variable_override(task=self._task, variables=vars_copy, templar=templar) - # TODO: eventually remove this block as this should be a 'consequence' of 'forced_local' modules + # TODO: eventually remove this block as this should be a 'consequence' of 'forced_local' modules, right now rely on remote_is_local connection # special handling for python interpreter for network_os, default to ansible python unless overridden - if 'ansible_network_os' in cvars and 'ansible_python_interpreter' not in cvars: + if 'ansible_python_interpreter' not in cvars and 'ansible_network_os' in cvars and getattr(self._connection, '_remote_is_local', False): # this also avoids 'python discovery' cvars['ansible_python_interpreter'] = sys.executable