Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ansible: Respect interpreter_python config #833

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions ansible_mitogen/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ def get_task_var(self, key, default=None):
does not make sense to extract connection-related configuration for the
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
"""
Expand All @@ -651,15 +651,16 @@ def _fetch_task_var(task_vars, key):
escape_backslashes=False
)
return val
return default

task_vars = self._get_task_vars()
if self.delegate_to_hostname is None:
return _fetch_task_var(task_vars, key)
return _fetch_task_var(task_vars, key, default)
else:
delegated_vars = task_vars['ansible_delegated_vars']
if self.delegate_to_hostname in delegated_vars:
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

Expand Down
7 changes: 6 additions & 1 deletion ansible_mitogen/transport_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,9 @@ def port(self):
return self._connection_option('port')

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
# "/usr/bin/python" as the default interpreter path if no other
# interpreter is specified.
Expand Down Expand Up @@ -703,6 +705,9 @@ def port(self):

def python_path(self, rediscover_python=False):
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
# "/usr/bin/python" as the default interpreter path if no other
# interpreter is specified.
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ In progress (unreleased)
with `meta: reset_connection`
* :gh:issue:`1083` :mod:`ansible_mitogen`: Templated connection timeout
(e.g. ``ansible_timeout``).
* :gh:issue:`740` respect `interpreter_python` global configuration variable


v0.3.19 (2024-12-02)
Expand Down
Loading