ansible: Respect interpreter_python config variable

This commit is contained in:
Lars Beckers 2021-04-29 22:43:54 +02:00
parent 36f3e3b28c
commit afe0026890
3 changed files with 11 additions and 4 deletions

View File

@ -623,7 +623,7 @@ class Connection(ansible.plugins.connection.ConnectionBase):
does not make sense to extract connection-related configuration for the does not make sense to extract connection-related configuration for the
delegated-to machine from them. delegated-to machine from them.
""" """
def _fetch_task_var(task_vars, key): def _fetch_task_var(task_vars, key, default):
""" """
Special helper func in case vars can be templated Special helper func in case vars can be templated
""" """
@ -641,15 +641,16 @@ class Connection(ansible.plugins.connection.ConnectionBase):
escape_backslashes=False escape_backslashes=False
) )
return val return val
return default
task_vars = self._get_task_vars() task_vars = self._get_task_vars()
if self.delegate_to_hostname is None: if self.delegate_to_hostname is None:
return _fetch_task_var(task_vars, key) return _fetch_task_var(task_vars, key, default)
else: else:
delegated_vars = task_vars['ansible_delegated_vars'] delegated_vars = task_vars['ansible_delegated_vars']
if self.delegate_to_hostname in delegated_vars: if self.delegate_to_hostname in delegated_vars:
task_vars = delegated_vars[self.delegate_to_hostname] task_vars = delegated_vars[self.delegate_to_hostname]
return _fetch_task_var(task_vars, key) return _fetch_task_var(task_vars, key, default)
return default return default

View File

@ -437,7 +437,9 @@ class PlayContextSpec(Spec):
return self._play_context.port return self._play_context.port
def python_path(self, rediscover_python=False): def python_path(self, rediscover_python=False):
s = self._connection.get_task_var('ansible_python_interpreter') s = self._connection.get_task_var('ansible_python_interpreter',
default=C.config.get_config_value('INTERPRETER_PYTHON',
variables=self._task_vars))
# #511, #536: executor/module_common.py::_get_shebang() hard-wires # #511, #536: executor/module_common.py::_get_shebang() hard-wires
# "/usr/bin/python" as the default interpreter path if no other # "/usr/bin/python" as the default interpreter path if no other
# interpreter is specified. # interpreter is specified.
@ -661,6 +663,9 @@ class MitogenViaSpec(Spec):
def python_path(self, rediscover_python=False): def python_path(self, rediscover_python=False):
s = self._host_vars.get('ansible_python_interpreter') s = self._host_vars.get('ansible_python_interpreter')
if s is None:
s = C.config.get_config_value('INTERPRETER_PYTHON',
variables=self._task_vars)
# #511, #536: executor/module_common.py::_get_shebang() hard-wires # #511, #536: executor/module_common.py::_get_shebang() hard-wires
# "/usr/bin/python" as the default interpreter path if no other # "/usr/bin/python" as the default interpreter path if no other
# interpreter is specified. # interpreter is specified.

View File

@ -26,6 +26,7 @@ This release separates itself from the v0.2.X releases. Ansible's API changed to
* :gh:issue:`770` better check for supported Ansible version * :gh:issue:`770` better check for supported Ansible version
* :gh:issue:`731` ansible 2.10 support * :gh:issue:`731` ansible 2.10 support
* :gh:issue:`652` support for ansible collections import hook * :gh:issue:`652` support for ansible collections import hook
* :gh:issue:`740` respect `interpreter_python` global configuration variable
v0.2.10 (unreleased) v0.2.10 (unreleased)