Skip to content

Commit

Permalink
WIP discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
moreati committed Jan 20, 2025
1 parent 177d1dd commit 1587cfb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
14 changes: 5 additions & 9 deletions ansible_mitogen/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,9 @@ def __init__(self, task, connection, *args, **kwargs):

# required for python interpreter discovery
connection.templar = self._templar
self._finding_python_interpreter = False
self._rediscovered_python = False
# redeclaring interpreter discovery vars here in case running ansible < 2.8.0
self._discovered_interpreter_key = None
self._discovered_interpreter = False
self._discovery_deprecation_warnings = []
self._discovery_warnings = []

self._mitogen_discovering_interpreter = False
self._mitogen_rediscovered_interpreter = False

def run(self, tmp=None, task_vars=None):
"""
Expand Down Expand Up @@ -402,7 +398,7 @@ def _execute_module(self, module_name=None, module_args=None, tmp=None,
# only cache discovered_interpreter if we're not running a rediscovery
# rediscovery happens in places like docker connections that could have different
# python interpreters than the main host
if not self._rediscovered_python:
if not self._mitogen_rediscovered_interpreter:
result['ansible_facts'][self._discovered_interpreter_key] = self._discovered_interpreter

if self._discovery_warnings:
Expand Down Expand Up @@ -462,7 +458,7 @@ def _low_level_execute_command(self, cmd, sudoable=True, in_data=None,
# calling exec_command until we run into the right python we'll use
# chicken-and-egg issue, mitogen needs a python to run low_level_execute_command
# which is required by Ansible's discover_interpreter function
if self._finding_python_interpreter:
if self._mitogen_discovering_interpreter:
possible_pythons = [
'/usr/bin/python',
'python3',
Expand Down
8 changes: 4 additions & 4 deletions ansible_mitogen/transport_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def run_interpreter_discovery_if_necessary(s, task_vars, action, rediscover_pyth
it could be different than what's ran on the host
"""
# keep trying different interpreters until we don't error
if action._finding_python_interpreter:
if action._mitogen_discovering_interpreter:
return action._possible_python_interpreter

if s in ['auto', 'auto_legacy', 'auto_silent', 'auto_legacy_silent']:
Expand All @@ -102,13 +102,13 @@ def run_interpreter_discovery_if_necessary(s, task_vars, action, rediscover_pyth
# if we're rediscovering python then chances are we're running something like a docker connection
# this will handle scenarios like running a playbook that does stuff + then dynamically creates a docker container,
# then runs the rest of the playbook inside that container, and then rerunning the playbook again
action._rediscovered_python = True
action._mitogen_rediscovered_interpreter = True

# blow away the discovered_interpreter_config cache and rediscover
del task_vars['ansible_facts'][discovered_interpreter_config]

if discovered_interpreter_config not in task_vars['ansible_facts']:
action._finding_python_interpreter = True
action._mitogen_discovering_interpreter = True
# fake pipelining so discover_interpreter can be happy
action._connection.has_pipelining = True
s = ansible.executor.interpreter_discovery.discover_interpreter(
Expand All @@ -128,7 +128,7 @@ def run_interpreter_discovery_if_necessary(s, task_vars, action, rediscover_pyth
action._discovered_interpreter_key = discovered_interpreter_config
action._discovered_interpreter = s

action._finding_python_interpreter = False
action._mitogen_discovering_interpreter = False
return s


Expand Down

0 comments on commit 1587cfb

Please sign in to comment.