diff --git a/ansible_mitogen/transport_config.py b/ansible_mitogen/transport_config.py index 937755528..effb4d62e 100644 --- a/ansible_mitogen/transport_config.py +++ b/ansible_mitogen/transport_config.py @@ -493,12 +493,24 @@ def port(self): return self._connection_option('port') def python_path(self, rediscover_python=False): - s = self._connection.get_task_var('ansible_python_interpreter') - # #511, #536: executor/module_common.py::_get_shebang() hard-wires - # "/usr/bin/python" as the default interpreter path if no other - # interpreter is specified. + # See also + # - ansible_mitogen.connecton.Connection.get_task_var() + try: + delegated_vars = self._task_vars['ansible_delegated_vars'] + variables = delegated_vars[self._connection.delegate_to_hostname] + except KeyError: + variables = self._task_vars + + interpreter_python = C.config.get_config_value( + 'INTERPRETER_PYTHON', variables=variables, + ) + + if '{{' in interpreter_python or '{%' in interpreter_python: + templar = self._connection.templar + interpreter_python = templar.template(interpreter_python) + return parse_python_path( - s, + interpreter_python, task_vars=self._task_vars, action=self._action, rediscover_python=rediscover_python) diff --git a/docs/changelog.rst b/docs/changelog.rst index 23d3b327d..13a698fcd 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -27,6 +27,8 @@ In progress (unreleased) with `meta: reset_connection` * :gh:issue:`1083` :mod:`ansible_mitogen`: Templated connection timeout (e.g. ``ansible_timeout``). +* :gh:issue:`740` :mod:`ansible_mitogen`: Respect ``interpreter_python`` + in ``ansible.cfg`` and ``ANSIBLE_PYTHON_INTERPRETER`` environment variable. v0.3.19 (2024-12-02) diff --git a/tests/ansible/hosts/default.hosts b/tests/ansible/hosts/default.hosts index 3d20e73df..a99352b36 100644 --- a/tests/ansible/hosts/default.hosts +++ b/tests/ansible/hosts/default.hosts @@ -50,6 +50,7 @@ tt-host-key-checking ansible_host=localhost ansible_host_key_checking= tt-password ansible_host=localhost ansible_password="{{ 'has_sudo_nopw_password' | trim }}" ansible_user=mitogen__has_sudo_nopw tt-port ansible_host=localhost ansible_password=has_sudo_nopw_password ansible_port="{{ 22 | int }}" ansible_user=mitogen__has_sudo_nopw tt-private-key-file ansible_host=localhost ansible_private_key_file="{{ git_basedir }}/tests/data/docker/mitogen__has_sudo_pubkey.key" ansible_user=mitogen__has_sudo_pubkey +tt-python-interpreter ansible_host=localhost ansible_password=has_sudo_nopw_password ansible_python_interpreter="{{ ansible_playbook_python | trim }}" ansible_user=mitogen__has_sudo_nopw tt-remote-user ansible_host=localhost ansible_password=has_sudo_nopw_password ansible_user="{{ 'mitogen__has_sudo_nopw' | trim }}" tt-ssh-executable ansible_host=localhost ansible_password=has_sudo_nopw_password ansible_ssh_executable="{{ 'ssh' | trim }}" ansible_user=mitogen__has_sudo_nopw tt-timeout ansible_host=localhost ansible_password=has_sudo_nopw_password ansible_timeout="{{ 5 | int }}" ansible_user=mitogen__has_sudo_nopw diff --git a/tests/ansible/templates/test-targets.j2 b/tests/ansible/templates/test-targets.j2 index 65f2fd7d9..063847ccb 100644 --- a/tests/ansible/templates/test-targets.j2 +++ b/tests/ansible/templates/test-targets.j2 @@ -84,6 +84,7 @@ tt-host-key-checking ansible_host={{ tt.hostname }} ansible_host_key_c tt-password ansible_host={{ tt.hostname }} ansible_password="{{ '{{' }} 'has_sudo_nopw_password' | trim {{ '}}' }}" ansible_port={{ tt.port }} ansible_python_interpreter={{ tt.python_path }} ansible_user=mitogen__has_sudo_nopw tt-port ansible_host={{ tt.hostname }} ansible_password=has_sudo_nopw_password ansible_port="{{ '{{' }} {{ tt.port }} | int {{ '}}' }}" ansible_python_interpreter={{ tt.python_path }} ansible_user=mitogen__has_sudo_nopw tt-private-key-file ansible_host={{ tt.hostname }} ansible_port={{ tt.port }} ansible_private_key_file="{{ '{{' }} git_basedir {{ '}}' }}/tests/data/docker/mitogen__has_sudo_pubkey.key" ansible_python_interpreter={{ tt.python_path }} ansible_user=mitogen__has_sudo_pubkey +tt-python-interpreter ansible_host={{ tt.hostname }} ansible_port={{ tt.port }} ansible_password=has_sudo_nopw_password ansible_python_interpreter="{{ '{{' }} '{{ tt.python_path }}' | trim {{ '}}' }}" ansible_user=mitogen__has_sudo_nopw tt-remote-user ansible_host={{ tt.hostname }} ansible_password=has_sudo_nopw_password ansible_port={{ tt.port }} ansible_python_interpreter={{ tt.python_path }} ansible_user="{{ '{{' }} 'mitogen__has_sudo_nopw' | trim {{ '}}' }}" tt-ssh-executable ansible_host={{ tt.hostname }} ansible_password=has_sudo_nopw_password ansible_port={{ tt.port }} ansible_python_interpreter={{ tt.python_path }} ansible_ssh_executable="{{ '{{' }} 'ssh' | trim {{ '}}' }}" ansible_user=mitogen__has_sudo_nopw tt-timeout ansible_host={{ tt.hostname }} ansible_password=has_sudo_nopw_password ansible_port={{ tt.port }} ansible_python_interpreter={{ tt.python_path }} ansible_timeout="{{ '{{' }} 5 | int {{ '}}' }}" ansible_user=mitogen__has_sudo_nopw