Allow to set python interper for ansible execution
Some environment still use python2.7 and so /usr/bin/python interpreter for ansible. In that case, Ansible will fail to execute. This option allow the user to pass a specific python interpeter for the remote. In None python_interpreter, and connection local is set we use the local sys.executable, if both are None we use the default. Change-Id: I4bd25ed50091a963d0b1e5e3a727ece19b90747e
This commit is contained in:
parent
15e74046c1
commit
1ac91f1f31
|
@ -122,7 +122,7 @@ class Ansible(object):
|
|||
def _ansible_env_var(self, output_callback, ssh_user, workdir, connection,
|
||||
gathering_policy, module_path, key,
|
||||
extra_env_variables, ansible_timeout,
|
||||
callback_whitelist, base_dir):
|
||||
callback_whitelist, base_dir, python_interpreter):
|
||||
"""Handle Ansible env var for Ansible config execution"""
|
||||
cwd = os.getcwd()
|
||||
env = os.environ.copy()
|
||||
|
@ -226,7 +226,9 @@ class Ansible(object):
|
|||
if self.uuid:
|
||||
env['ANSIBLE_UUID'] = self.uuid
|
||||
|
||||
if connection == 'local':
|
||||
if python_interpreter:
|
||||
env['ANSIBLE_PYTHON_INTERPRETER'] = python_interpreter
|
||||
elif connection == 'local':
|
||||
env['ANSIBLE_PYTHON_INTERPRETER'] = sys.executable
|
||||
|
||||
if gathering_policy in ('smart', 'explicit', 'implicit'):
|
||||
|
@ -280,7 +282,7 @@ class Ansible(object):
|
|||
extra_env_variables=None, parallel_run=False,
|
||||
callback_whitelist=None, ansible_cfg=None,
|
||||
ansible_timeout=30, ansible_artifact_path=None,
|
||||
log_path=None, run_async=False):
|
||||
log_path=None, run_async=False, python_interpreter=None):
|
||||
|
||||
if not playbook_dir:
|
||||
playbook_dir = workdir
|
||||
|
@ -305,7 +307,8 @@ class Ansible(object):
|
|||
env = self._ansible_env_var(output_callback, ssh_user, workdir,
|
||||
connection, gathering_policy, module_path,
|
||||
key, extra_env_variables, ansible_timeout,
|
||||
callback_whitelist, base_dir)
|
||||
callback_whitelist, base_dir,
|
||||
python_interpreter)
|
||||
if not ansible_artifact_path:
|
||||
ansible_artifact_path = constants.VALIDATION_ANSIBLE_ARTIFACT_PATH
|
||||
if 'ANSIBLE_CONFIG' not in env and not ansible_cfg:
|
||||
|
|
|
@ -68,7 +68,7 @@ class ValidationActions(object):
|
|||
extra_env_vars=None, ansible_cfg=None, quiet=True,
|
||||
workdir=None, limit_hosts=None, run_async=False,
|
||||
base_dir=constants.DEFAULT_VALIDATIONS_BASEDIR,
|
||||
log_path=None):
|
||||
log_path=None, python_interpreter=None):
|
||||
self.log = logging.getLogger(__name__ + ".run_validations")
|
||||
playbooks = []
|
||||
validations_dir = (validations_dir if validations_dir
|
||||
|
@ -115,7 +115,8 @@ class ValidationActions(object):
|
|||
gathering_policy='explicit',
|
||||
ansible_artifact_path=artifacts_dir,
|
||||
log_path=log_path,
|
||||
run_async=run_async)
|
||||
run_async=run_async,
|
||||
python_interpreter=python_interpreter)
|
||||
results.append({'playbook': _playbook,
|
||||
'rc_code': _rc,
|
||||
'status': _status,
|
||||
|
|
Loading…
Reference in New Issue