From 52bcf4a195160dfff306d4497f4609bef38216e5 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Thu, 22 Jan 2015 18:05:54 -0800 Subject: [PATCH] Don't fial if virtualenv is not installed and we do not need to initialize the virtualenv Fixes #688 --- lib/ansible/modules/packaging/language/pip.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/ansible/modules/packaging/language/pip.py b/lib/ansible/modules/packaging/language/pip.py index 17f52c00398..97576a5258b 100644 --- a/lib/ansible/modules/packaging/language/pip.py +++ b/lib/ansible/modules/packaging/language/pip.py @@ -98,7 +98,7 @@ options: required: false default: null notes: - - Please note that virtualenv (U(http://www.virtualenv.org/)) must be installed on the remote host if the virtualenv parameter is specified. + - Please note that virtualenv (U(http://www.virtualenv.org/)) must be installed on the remote host if the virtualenv parameter is specified and the virtualenv needs to be initialized. requirements: [ "virtualenv", "pip" ] author: Matt Wright ''' @@ -252,12 +252,14 @@ def main(): if env: env = os.path.expanduser(env) - virtualenv = os.path.expanduser(virtualenv_command) - if os.path.basename(virtualenv) == virtualenv: - virtualenv = module.get_bin_path(virtualenv_command, True) if not os.path.exists(os.path.join(env, 'bin', 'activate')): if module.check_mode: module.exit_json(changed=True) + + virtualenv = os.path.expanduser(virtualenv_command) + if os.path.basename(virtualenv) == virtualenv: + virtualenv = module.get_bin_path(virtualenv_command, True) + if module.params['virtualenv_site_packages']: cmd = '%s --system-site-packages %s' % (virtualenv, env) else: @@ -278,7 +280,7 @@ def main(): pip = _get_pip(module, env, module.params['executable']) cmd = '%s %s' % (pip, state_map[state]) - + # If there's a virtualenv we want things we install to be able to use other # installations that exist as binaries within this virtualenv. Example: we # install cython and then gevent -- gevent needs to use the cython binary, @@ -308,7 +310,7 @@ def main(): cmd += ' %s' % _get_full_name(name, version) elif requirements: cmd += ' -r %s' % requirements - + this_dir = tempfile.gettempdir() if chdir: this_dir = os.path.join(this_dir, chdir) @@ -319,7 +321,7 @@ def main(): elif name.startswith('svn+') or name.startswith('git+') or \ name.startswith('hg+') or name.startswith('bzr+'): module.exit_json(changed=True) - + freeze_cmd = '%s freeze' % pip rc, out_pip, err_pip = module.run_command(freeze_cmd, cwd=this_dir)