Pass the python interpreter to the play command directly

Ansible doesn't take into account any 'ANSIBLE_PYTHON_INTERPRETER' env
var, as per this comment[1] back in 2016.

We hence have to pass it as an extra variable directly in the command.

This patch corrects I0600218163269409ae35ca34ffdfedb57926424e in
order to ensure we do pass the python interpreter value correctly.

[1] https://github.com/ansible/ansible/issues/6345#issuecomment-181981760

Change-Id: I48c8c532b23b9422406168cecdc9aebfe8f45651
Blueprint: python-3
This commit is contained in:
Cédric Jeanneret 2019-01-17 12:19:46 +01:00
parent 81669071ed
commit c163a42668

View File

@ -110,16 +110,18 @@ def run_ansible_playbook(logger,
elif os.path.exists(os.path.join(workdir, ansible_config)):
env['ANSIBLE_CONFIG'] = os.path.join(workdir, ansible_config)
if python_interpreter is not None:
env['ANSIBLE_PYTHON_INTERPRETER'] = python_interpreter
play = os.path.join(workdir, playbook)
if os.path.exists(play):
cmd = ["ansible-playbook-{}".format(sys.version_info[0]),
'-i', inventory,
'-c', connection, play
]
if python_interpreter is not None:
cmd.extend(['-e', 'ansible_python_interpreter=%s' %
python_interpreter])
cmd.extend(['-c', connection, play])
proc = run_command_and_log(logger, cmd, env=env, retcode_only=False)
proc.wait()
cleanup and os.unlink(tmp_config)