From ff6bac126e65666da657222f1a0d0f1884117f9f Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Thu, 20 Oct 2016 13:09:58 -0700 Subject: [PATCH] On Ubuntu16, virtualenv always tries to use python2 even when python2 is not installed. Workaround that by mimicing the upstream virtualenv behaviour in code (use the python version that was used to invoke virtualenv/the ansible module) --- lib/ansible/modules/packaging/language/pip.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/packaging/language/pip.py b/lib/ansible/modules/packaging/language/pip.py index 405c2308b9e..95cd7caf5f6 100755 --- a/lib/ansible/modules/packaging/language/pip.py +++ b/lib/ansible/modules/packaging/language/pip.py @@ -79,7 +79,7 @@ options: description: - The Python executable used for creating the virtual environment. For example C(python3.5), C(python2.7). When not specified, the - system Python version is used. + Python version used to run the ansible module is used. required: false default: null state: @@ -415,6 +415,14 @@ def main(): if virtualenv_python: cmd += ' -p%s' % virtualenv_python + elif PY3: + # Ubuntu currently has a patch making virtualenv always + # try to use python2. Since Ubuntu16 works without + # python2 installed, this is a problem. This code mimics + # the upstream behaviour of using the python which invoked + # virtualenv to determine which python is used inside of + # the virtualenv (when none are specified). + cmd += ' -p%s' % sys.executable cmd = "%s %s" % (cmd, env) rc, out_venv, err_venv = module.run_command(cmd, cwd=chdir)