trying to get docker rhel8 working on a Mac host

pull/658/head
Steven Robertson 5 years ago
parent cd3b88d9e3
commit 7d6d76e444

@ -183,7 +183,7 @@ def _connect_docker(spec):
'kwargs': { 'kwargs': {
'username': spec.remote_user(), 'username': spec.remote_user(),
'container': spec.remote_addr(), 'container': spec.remote_addr(),
'python_path': spec.python_path(), 'python_path': spec.python_path(rediscover_python=True),
'connect_timeout': spec.ansible_ssh_timeout() or spec.timeout(), 'connect_timeout': spec.ansible_ssh_timeout() or spec.timeout(),
'remote_name': get_remote_name(spec), 'remote_name': get_remote_name(spec),
} }

@ -451,6 +451,7 @@ class ActionModuleMixin(ansible.plugins.action.ActionBase):
""" """
LOG.debug('_low_level_execute_command(%r, in_data=%r, exe=%r, dir=%r)', LOG.debug('_low_level_execute_command(%r, in_data=%r, exe=%r, dir=%r)',
cmd, type(in_data), executable, chdir) cmd, type(in_data), executable, chdir)
if executable is None: # executable defaults to False if executable is None: # executable defaults to False
executable = self._play_context.executable executable = self._play_context.executable
if executable: if executable:

@ -81,26 +81,26 @@ except ImportError:
import mitogen.core import mitogen.core
def run_interpreter_discovery_if_necessary(s, task_vars, action): def run_interpreter_discovery_if_necessary(s, task_vars, action, rediscover_python):
""" """
Triggers ansible python interpreter discovery if requested. Triggers ansible python interpreter discovery if requested.
Caches this value the same way Ansible does it. Caches this value the same way Ansible does it.
For connections like `docker`, we want to rediscover the python interpreter because
it could be different than what's ran on the host
""" """
# _finding_python_interpreter is a special case where we've already called discover_interpreter which then # TODO: avoid infinite recursion via _finding_python_interpreter + low_level_execute_command called from discover_interpreter
# 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 or s is None:
return '/usr/bin/python'
if s in ['auto', 'auto_legacy', 'auto_silent', 'auto_legacy_silent']: if s in ['auto', 'auto_legacy', 'auto_silent', 'auto_legacy_silent']:
# python is the only supported interpreter_name as of Ansible 2.8.6 # python is the only supported interpreter_name as of Ansible 2.8.8
interpreter_name = 'python' interpreter_name = 'python'
discovered_interpreter_config = u'discovered_interpreter_%s' % interpreter_name discovered_interpreter_config = u'discovered_interpreter_%s' % interpreter_name
if task_vars.get('ansible_facts') is None: if task_vars.get('ansible_facts') is None:
task_vars['ansible_facts'] = {} task_vars['ansible_facts'] = {}
if rediscover_python and task_vars.get('ansible_facts', {}).get(discovered_interpreter_config):
# 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']: if discovered_interpreter_config not in task_vars['ansible_facts']:
action._finding_python_interpreter = True action._finding_python_interpreter = True
# fake pipelining so discover_interpreter can be happy # fake pipelining so discover_interpreter can be happy
@ -124,15 +124,22 @@ def run_interpreter_discovery_if_necessary(s, task_vars, action):
return s return s
def parse_python_path(s, task_vars, action): def parse_python_path(s, task_vars, action, rediscover_python):
""" """
Given the string set for ansible_python_interpeter, parse it using shell Given the string set for ansible_python_interpeter, parse it using shell
syntax and return an appropriate argument vector. If the value detected is syntax and return an appropriate argument vector. If the value detected is
one of interpreter discovery then run that first. Caches python interpreter one of interpreter discovery then run that first. Caches python interpreter
discovery value in `facts_from_task_vars` like how Ansible handles this. discovery value in `facts_from_task_vars` like how Ansible handles this.
""" """
if s: if not s:
s = run_interpreter_discovery_if_necessary(s, task_vars, action) # if python_path doesn't exist, default to `auto` and attempt to discover it
s = 'auto'
s = run_interpreter_discovery_if_necessary(s, task_vars, action, rediscover_python)
# if unable to determine python_path, fallback to '/usr/bin/python'
if not s:
s = '/usr/bin/python'
return ansible.utils.shlex.shlex_split(s) return ansible.utils.shlex.shlex_split(s)
@ -420,15 +427,16 @@ class PlayContextSpec(Spec):
def port(self): def port(self):
return self._play_context.port return self._play_context.port
def python_path(self): 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')
# #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.
return parse_python_path( return parse_python_path(
s or '/usr/bin/python', s,
task_vars=self._task_vars, task_vars=self._task_vars,
action=self._action) action=self._action,
rediscover_python=rediscover_python)
def private_key_file(self): def private_key_file(self):
return self._play_context.private_key_file return self._play_context.private_key_file
@ -642,15 +650,16 @@ class MitogenViaSpec(Spec):
C.DEFAULT_REMOTE_PORT C.DEFAULT_REMOTE_PORT
) )
def python_path(self): def python_path(self, rediscover_python=False):
s = self._host_vars.get('ansible_python_interpreter') s = self._host_vars.get('ansible_python_interpreter')
# #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.
return parse_python_path( return parse_python_path(
s or '/usr/bin/python', s,
task_vars=self._task_vars, task_vars=self._task_vars,
action=self._action) action=self._action,
rediscover_python=rediscover_python)
def private_key_file(self): def private_key_file(self):
# TODO: must come from PlayContext too. # TODO: must come from PlayContext too.

Loading…
Cancel
Save