From 9f65233e966d24c56330ac14efaa5147265c801e Mon Sep 17 00:00:00 2001 From: Jeroen Hoekx Date: Wed, 20 Feb 2013 14:52:02 +0100 Subject: [PATCH] Easy_install and pip module support a virtualenv_command parameter. This allows flexible selection of the Python version to use while creating the virtualenv. --- library/easy_install | 10 +++++++++- library/pip | 12 +++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/library/easy_install b/library/easy_install index 4ba57b3cba..0096cd1fff 100644 --- a/library/easy_install +++ b/library/easy_install @@ -48,6 +48,12 @@ options: created. required: false default: no + virtualenv_command: + description: + - The command to create the virtual environment with. For example + C(pyvenv), C(virtualenv), C(virtualenv2). + required: false + default: virtualenv examples: - code: "easy_install: name=pip" description: "Examples from Ansible Playbooks" @@ -75,6 +81,7 @@ def main(): name=dict(required=True), virtualenv=dict(default=None, required=False), virtualenv_site_packages=dict(default='no', choices=BOOLEANS), + virtualenv_command=dict(default='virtualenv', required=False), ) module = AnsibleModule(argument_spec=arg_spec) @@ -83,13 +90,14 @@ def main(): env = module.params['virtualenv'] easy_install = module.get_bin_path('easy_install', True, ['%s/bin' % env]) site_packages = module.boolean(module.params['virtualenv_site_packages']) + virtualenv_command = module.params['virtualenv_command'] rc = 0 err = '' out = '' if env: - virtualenv = module.get_bin_path('virtualenv', True) + virtualenv = module.get_bin_path(virtualenv_command, True) if not os.path.exists(os.path.join(env, 'bin', 'activate')): command = '%s %s' % (virtualenv, env) diff --git a/library/pip b/library/pip index 289072c604..7172966fe5 100644 --- a/library/pip +++ b/library/pip @@ -56,6 +56,12 @@ options: created. required: false default: no + virtualenv_command: + description: + - The command to create the virtual environment with. For example + C(pyvenv), C(virtualenv), C(virtualenv2). + required: false + default: virtualenv use_mirrors: description: - Whether to use mirrors when installing python libraries. If using @@ -86,6 +92,8 @@ examples: description: "Install I(Flask) (U(http://flask.pocoo.org/)) into the specified I(virtualenv), inheriting none of the globally installed modules" - code: "pip: name=flask virtualenv=/my_app/venv virtualenv_site_packages=yes" description: "Install I(Flask) (U(http://flask.pocoo.org/)) into the specified I(virtualenv), inheriting globally installed modules" + - code: "pip: name=flask virtualenv=/my_app/venv virtualenv_command=virtualenv-2.7" + description: "Install I(Flask) (U(http://flask.pocoo.org/)) into the specified I(virtualenv), using Python 2.7" - code: "pip: requirements=/my_app/requirements.txt" description: Install specified python requirements. - code: "pip: requirements=/my_app/requirements.txt virtualenv=/my_app/venv" @@ -149,6 +157,7 @@ def main(): requirements=dict(default=None, required=False), virtualenv=dict(default=None, required=False), virtualenv_site_packages=dict(default='no', choices=BOOLEANS), + virtualenv_command=dict(default='virtualenv', required=False), use_mirrors=dict(default='yes', choices=BOOLEANS), extra_args=dict(default=None, required=False), ), @@ -172,9 +181,10 @@ def main(): out = '' env = module.params['virtualenv'] + virtualenv_command = module.params['virtualenv_command'] if env: - virtualenv = module.get_bin_path('virtualenv', True) + virtualenv = module.get_bin_path(virtualenv_command, True) if not os.path.exists(os.path.join(env, 'bin', 'activate')): if module.boolean(module.params['virtualenv_site_packages']): cmd = '%s --system-site-packages %s' % (virtualenv, env)