diff --git a/ansible_mitogen/connection.py b/ansible_mitogen/connection.py index 8f7dd735..810eb90b 100644 --- a/ansible_mitogen/connection.py +++ b/ansible_mitogen/connection.py @@ -503,6 +503,9 @@ class Connection(ansible.plugins.connection.ConnectionBase): #: matching vanilla Ansible behaviour. loader_basedir = None + # set by `_get_task_vars()` for interpreter discovery + _action = None + def __del__(self): """ Ansible cannot be trusted to always call close() e.g. the synchronize diff --git a/ansible_mitogen/transport_config.py b/ansible_mitogen/transport_config.py index ff22c0fb..92456dba 100644 --- a/ansible_mitogen/transport_config.py +++ b/ansible_mitogen/transport_config.py @@ -83,11 +83,11 @@ def run_interpreter_discovery_if_necessary(s, task_vars, action): Triggers ansible python interpreter discovery if requested. Caches this value the same way Ansible does it. """ - # special case where we've already called discover_interpreter which then + # _finding_python_interpreter is a special case where we've already called discover_interpreter which then # calls low_level_exec_command which then retriggers spec.python_path() # in connect_ssh(), so we'll return the default '/usr/bin/python' to finish building the stack # TODO: possible issues here? Chicken-and-egg issue, in order to `connect_ssh` we need a python path - if action._finding_python_interpreter: + if action is None or action._finding_python_interpreter or s is None: return '/usr/bin/python' if s in ['auto', 'auto_legacy', 'auto_silent', 'auto_legacy_silent']: