2012-08-07 22:38:04 +02:00
|
|
|
#!/usr/bin/python
|
2012-08-08 16:35:07 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# (c) 2012, Matt Wright <matt@nobien.net>
|
|
|
|
#
|
|
|
|
# This file is part of Ansible
|
|
|
|
#
|
|
|
|
# Ansible is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# Ansible is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
2012-08-07 22:38:04 +02:00
|
|
|
|
2013-03-15 23:05:21 +01:00
|
|
|
import tempfile
|
|
|
|
|
2012-09-29 20:53:28 +02:00
|
|
|
DOCUMENTATION = '''
|
|
|
|
---
|
|
|
|
module: pip
|
|
|
|
short_description: Manages Python library dependencies.
|
|
|
|
description:
|
|
|
|
- Manage Python library dependencies.
|
|
|
|
version_added: "0.7"
|
|
|
|
options:
|
|
|
|
name:
|
|
|
|
description:
|
|
|
|
- The name of a Python library to install
|
2013-03-14 03:25:58 +01:00
|
|
|
required: false
|
2012-09-29 20:53:28 +02:00
|
|
|
default: null
|
|
|
|
version:
|
|
|
|
description:
|
2012-11-21 18:49:30 +01:00
|
|
|
- The version number to install of the Python library specified in the I(name) parameter
|
2012-09-29 20:53:28 +02:00
|
|
|
required: false
|
|
|
|
default: null
|
|
|
|
requirements:
|
|
|
|
description:
|
|
|
|
- The path to a pip requirements file
|
|
|
|
required: false
|
|
|
|
default: null
|
|
|
|
virtualenv:
|
|
|
|
description:
|
2012-11-21 18:49:30 +01:00
|
|
|
- An optional path to a I(virtualenv) directory to install into
|
2012-09-29 20:53:28 +02:00
|
|
|
required: false
|
|
|
|
default: null
|
2013-01-29 18:30:09 +01:00
|
|
|
virtualenv_site_packages:
|
2013-03-30 20:44:34 +01:00
|
|
|
version_added: "1.0"
|
2013-01-29 18:30:09 +01:00
|
|
|
description:
|
|
|
|
- Whether the virtual environment will inherit packages from the
|
|
|
|
global site-packages directory. Note that if this setting is
|
|
|
|
changed on an already existing virtual environment it will not
|
|
|
|
have any effect, the environment must be deleted and newly
|
|
|
|
created.
|
|
|
|
required: false
|
2013-03-12 13:18:12 +01:00
|
|
|
default: "no"
|
|
|
|
choices: [ "yes", "no" ]
|
2013-02-20 14:52:02 +01:00
|
|
|
virtualenv_command:
|
2013-03-30 20:44:34 +01:00
|
|
|
version_aded: "1.1"
|
2013-02-20 14:52:02 +01:00
|
|
|
description:
|
|
|
|
- The command to create the virtual environment with. For example
|
|
|
|
C(pyvenv), C(virtualenv), C(virtualenv2).
|
|
|
|
required: false
|
|
|
|
default: virtualenv
|
2012-12-02 05:47:38 +01:00
|
|
|
use_mirrors:
|
|
|
|
description:
|
|
|
|
- Whether to use mirrors when installing python libraries. If using
|
|
|
|
an older version of pip (< 1.0), you should set this to no because
|
|
|
|
older versions of pip do not support I(--use-mirrors).
|
|
|
|
required: false
|
2013-03-12 13:18:12 +01:00
|
|
|
default: "yes"
|
2012-12-02 05:47:38 +01:00
|
|
|
choices: [ "yes", "no" ]
|
|
|
|
version_added: "1.0"
|
2012-09-29 20:53:28 +02:00
|
|
|
state:
|
|
|
|
description:
|
|
|
|
- The state of module
|
|
|
|
required: false
|
|
|
|
default: present
|
|
|
|
choices: [ "present", "absent", "latest" ]
|
pip module improvements
- Do not silently ignore malformed pip requirements files.
- Properly reports changed when removing packages.
- "latest" i.e. --upgrade is *not* incompatible with requirements files.
- Less branchy, simpler logic.
- Removed pointless variable "initializations", Python doesn't need that.
Other code simplifications.
- Fun fact; pip install is (kind of) case insensitive, pip freeze is not.
So, 'sqlalchemy' will be reported as installed by install, but missing
by freeze.
The perhaps controversial change and the one that led to finding /
fixing above issues...
Instead of adding command parameters 'index', and 'find', and 'mirrors',
and etc. Added 'extra_args' which are passed onto pip.
The use case for --index-url is having a private pypi repo, like
http://pypi.python.org/pypi/localshop, to which you publish private
packages. I'm sure most every pip option has a use case for someone.
extra_args handles all those. Can reserve ansible command parameters for
the most common.
Tested with pip 1.1.
2012-12-12 22:40:25 +01:00
|
|
|
extra_args:
|
|
|
|
description:
|
|
|
|
- Extra arguments passed to pip.
|
|
|
|
required: false
|
|
|
|
default: null
|
|
|
|
version_added: "1.0"
|
2012-09-29 20:53:28 +02:00
|
|
|
examples:
|
2012-10-23 15:14:01 +02:00
|
|
|
- code: "pip: name=flask"
|
2012-09-29 20:53:28 +02:00
|
|
|
description: Install I(flask) python package.
|
2012-10-23 15:14:01 +02:00
|
|
|
- code: "pip: name=flask version=0.8"
|
2012-09-29 20:53:28 +02:00
|
|
|
description: Install I(flask) python package on version 0.8.
|
pip module improvements
- Do not silently ignore malformed pip requirements files.
- Properly reports changed when removing packages.
- "latest" i.e. --upgrade is *not* incompatible with requirements files.
- Less branchy, simpler logic.
- Removed pointless variable "initializations", Python doesn't need that.
Other code simplifications.
- Fun fact; pip install is (kind of) case insensitive, pip freeze is not.
So, 'sqlalchemy' will be reported as installed by install, but missing
by freeze.
The perhaps controversial change and the one that led to finding /
fixing above issues...
Instead of adding command parameters 'index', and 'find', and 'mirrors',
and etc. Added 'extra_args' which are passed onto pip.
The use case for --index-url is having a private pypi repo, like
http://pypi.python.org/pypi/localshop, to which you publish private
packages. I'm sure most every pip option has a use case for someone.
extra_args handles all those. Can reserve ansible command parameters for
the most common.
Tested with pip 1.1.
2012-12-12 22:40:25 +01:00
|
|
|
- code: "pip: name=flask virtualenv=/my_app/venv"
|
2013-01-29 18:30:09 +01:00
|
|
|
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"
|
2013-02-20 14:52:02 +01:00
|
|
|
- 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"
|
pip module improvements
- Do not silently ignore malformed pip requirements files.
- Properly reports changed when removing packages.
- "latest" i.e. --upgrade is *not* incompatible with requirements files.
- Less branchy, simpler logic.
- Removed pointless variable "initializations", Python doesn't need that.
Other code simplifications.
- Fun fact; pip install is (kind of) case insensitive, pip freeze is not.
So, 'sqlalchemy' will be reported as installed by install, but missing
by freeze.
The perhaps controversial change and the one that led to finding /
fixing above issues...
Instead of adding command parameters 'index', and 'find', and 'mirrors',
and etc. Added 'extra_args' which are passed onto pip.
The use case for --index-url is having a private pypi repo, like
http://pypi.python.org/pypi/localshop, to which you publish private
packages. I'm sure most every pip option has a use case for someone.
extra_args handles all those. Can reserve ansible command parameters for
the most common.
Tested with pip 1.1.
2012-12-12 22:40:25 +01:00
|
|
|
- code: "pip: requirements=/my_app/requirements.txt"
|
2012-09-29 20:53:28 +02:00
|
|
|
description: Install specified python requirements.
|
pip module improvements
- Do not silently ignore malformed pip requirements files.
- Properly reports changed when removing packages.
- "latest" i.e. --upgrade is *not* incompatible with requirements files.
- Less branchy, simpler logic.
- Removed pointless variable "initializations", Python doesn't need that.
Other code simplifications.
- Fun fact; pip install is (kind of) case insensitive, pip freeze is not.
So, 'sqlalchemy' will be reported as installed by install, but missing
by freeze.
The perhaps controversial change and the one that led to finding /
fixing above issues...
Instead of adding command parameters 'index', and 'find', and 'mirrors',
and etc. Added 'extra_args' which are passed onto pip.
The use case for --index-url is having a private pypi repo, like
http://pypi.python.org/pypi/localshop, to which you publish private
packages. I'm sure most every pip option has a use case for someone.
extra_args handles all those. Can reserve ansible command parameters for
the most common.
Tested with pip 1.1.
2012-12-12 22:40:25 +01:00
|
|
|
- code: "pip: requirements=/my_app/requirements.txt virtualenv=/my_app/venv"
|
2012-11-21 18:49:30 +01:00
|
|
|
description: Install specified python requirements in indicated I(virtualenv).
|
pip module improvements
- Do not silently ignore malformed pip requirements files.
- Properly reports changed when removing packages.
- "latest" i.e. --upgrade is *not* incompatible with requirements files.
- Less branchy, simpler logic.
- Removed pointless variable "initializations", Python doesn't need that.
Other code simplifications.
- Fun fact; pip install is (kind of) case insensitive, pip freeze is not.
So, 'sqlalchemy' will be reported as installed by install, but missing
by freeze.
The perhaps controversial change and the one that led to finding /
fixing above issues...
Instead of adding command parameters 'index', and 'find', and 'mirrors',
and etc. Added 'extra_args' which are passed onto pip.
The use case for --index-url is having a private pypi repo, like
http://pypi.python.org/pypi/localshop, to which you publish private
packages. I'm sure most every pip option has a use case for someone.
extra_args handles all those. Can reserve ansible command parameters for
the most common.
Tested with pip 1.1.
2012-12-12 22:40:25 +01:00
|
|
|
- code: "pip: requirements=/my_app/requirements.txt extra_args='-i https://example.com/pypi/simple'"
|
|
|
|
description: Install specified python requirements and custom Index URL.
|
2012-09-29 20:53:28 +02:00
|
|
|
notes:
|
2013-03-19 19:12:54 +01:00
|
|
|
- Please note that virtualenv (U(http://www.virtualenv.org/)) must be installed on the remote host if the virtualenv parameter is specified.
|
2012-10-01 09:18:54 +02:00
|
|
|
requirements: [ "virtualenv", "pip" ]
|
2012-09-29 21:04:17 +02:00
|
|
|
author: Matt Wright
|
2012-09-29 20:53:28 +02:00
|
|
|
'''
|
2012-08-07 22:38:04 +02:00
|
|
|
|
pip module improvements
- Do not silently ignore malformed pip requirements files.
- Properly reports changed when removing packages.
- "latest" i.e. --upgrade is *not* incompatible with requirements files.
- Less branchy, simpler logic.
- Removed pointless variable "initializations", Python doesn't need that.
Other code simplifications.
- Fun fact; pip install is (kind of) case insensitive, pip freeze is not.
So, 'sqlalchemy' will be reported as installed by install, but missing
by freeze.
The perhaps controversial change and the one that led to finding /
fixing above issues...
Instead of adding command parameters 'index', and 'find', and 'mirrors',
and etc. Added 'extra_args' which are passed onto pip.
The use case for --index-url is having a private pypi repo, like
http://pypi.python.org/pypi/localshop, to which you publish private
packages. I'm sure most every pip option has a use case for someone.
extra_args handles all those. Can reserve ansible command parameters for
the most common.
Tested with pip 1.1.
2012-12-12 22:40:25 +01:00
|
|
|
|
2012-08-07 22:38:04 +02:00
|
|
|
def _get_full_name(name, version=None):
|
2012-08-09 23:54:29 +02:00
|
|
|
if version is None:
|
|
|
|
resp = name
|
|
|
|
else:
|
|
|
|
resp = name + '==' + version
|
|
|
|
return resp
|
2012-08-07 22:38:04 +02:00
|
|
|
|
|
|
|
|
pip module improvements
- Do not silently ignore malformed pip requirements files.
- Properly reports changed when removing packages.
- "latest" i.e. --upgrade is *not* incompatible with requirements files.
- Less branchy, simpler logic.
- Removed pointless variable "initializations", Python doesn't need that.
Other code simplifications.
- Fun fact; pip install is (kind of) case insensitive, pip freeze is not.
So, 'sqlalchemy' will be reported as installed by install, but missing
by freeze.
The perhaps controversial change and the one that led to finding /
fixing above issues...
Instead of adding command parameters 'index', and 'find', and 'mirrors',
and etc. Added 'extra_args' which are passed onto pip.
The use case for --index-url is having a private pypi repo, like
http://pypi.python.org/pypi/localshop, to which you publish private
packages. I'm sure most every pip option has a use case for someone.
extra_args handles all those. Can reserve ansible command parameters for
the most common.
Tested with pip 1.1.
2012-12-12 22:40:25 +01:00
|
|
|
def _get_pip(module, env):
|
|
|
|
# On Debian and Ubuntu, pip is pip.
|
|
|
|
# On Fedora18 and up, pip is python-pip.
|
|
|
|
# On Fedora17 and below, CentOS and RedHat 6 and 5, pip is pip-python.
|
|
|
|
# On Fedora, CentOS, and RedHat, the exception is in the virtualenv.
|
|
|
|
# There, pip is just pip.
|
|
|
|
# Try pip with the virtualenv directory first.
|
|
|
|
pip = module.get_bin_path('pip', False, ['%s/bin' % env])
|
|
|
|
for p in ['python-pip', 'pip-python']:
|
|
|
|
if not pip:
|
|
|
|
pip = module.get_bin_path(p, False, ['%s/bin' % env])
|
|
|
|
# pip should have been found by now. The final call to get_bin_path
|
|
|
|
# will trigger fail_json.
|
|
|
|
if not pip:
|
|
|
|
pip = module.get_bin_path('pip', True, ['%s/bin' % env])
|
|
|
|
return pip
|
2012-08-08 16:35:07 +02:00
|
|
|
|
|
|
|
|
pip module improvements
- Do not silently ignore malformed pip requirements files.
- Properly reports changed when removing packages.
- "latest" i.e. --upgrade is *not* incompatible with requirements files.
- Less branchy, simpler logic.
- Removed pointless variable "initializations", Python doesn't need that.
Other code simplifications.
- Fun fact; pip install is (kind of) case insensitive, pip freeze is not.
So, 'sqlalchemy' will be reported as installed by install, but missing
by freeze.
The perhaps controversial change and the one that led to finding /
fixing above issues...
Instead of adding command parameters 'index', and 'find', and 'mirrors',
and etc. Added 'extra_args' which are passed onto pip.
The use case for --index-url is having a private pypi repo, like
http://pypi.python.org/pypi/localshop, to which you publish private
packages. I'm sure most every pip option has a use case for someone.
extra_args handles all those. Can reserve ansible command parameters for
the most common.
Tested with pip 1.1.
2012-12-12 22:40:25 +01:00
|
|
|
def _fail(module, cmd, out, err):
|
|
|
|
msg = ''
|
|
|
|
if out:
|
|
|
|
msg += "stdout: %s" % (out, )
|
|
|
|
if err:
|
|
|
|
msg += "\n:stderr: %s" % (err, )
|
|
|
|
module.fail_json(cmd=cmd, msg=msg)
|
|
|
|
|
|
|
|
|
2012-08-07 22:38:04 +02:00
|
|
|
def main():
|
pip module improvements
- Do not silently ignore malformed pip requirements files.
- Properly reports changed when removing packages.
- "latest" i.e. --upgrade is *not* incompatible with requirements files.
- Less branchy, simpler logic.
- Removed pointless variable "initializations", Python doesn't need that.
Other code simplifications.
- Fun fact; pip install is (kind of) case insensitive, pip freeze is not.
So, 'sqlalchemy' will be reported as installed by install, but missing
by freeze.
The perhaps controversial change and the one that led to finding /
fixing above issues...
Instead of adding command parameters 'index', and 'find', and 'mirrors',
and etc. Added 'extra_args' which are passed onto pip.
The use case for --index-url is having a private pypi repo, like
http://pypi.python.org/pypi/localshop, to which you publish private
packages. I'm sure most every pip option has a use case for someone.
extra_args handles all those. Can reserve ansible command parameters for
the most common.
Tested with pip 1.1.
2012-12-12 22:40:25 +01:00
|
|
|
state_map = dict(
|
|
|
|
present='install',
|
|
|
|
absent='uninstall -y',
|
|
|
|
latest='install -U',
|
2012-08-07 22:38:04 +02:00
|
|
|
)
|
|
|
|
|
2012-08-12 00:13:29 +02:00
|
|
|
module = AnsibleModule(
|
pip module improvements
- Do not silently ignore malformed pip requirements files.
- Properly reports changed when removing packages.
- "latest" i.e. --upgrade is *not* incompatible with requirements files.
- Less branchy, simpler logic.
- Removed pointless variable "initializations", Python doesn't need that.
Other code simplifications.
- Fun fact; pip install is (kind of) case insensitive, pip freeze is not.
So, 'sqlalchemy' will be reported as installed by install, but missing
by freeze.
The perhaps controversial change and the one that led to finding /
fixing above issues...
Instead of adding command parameters 'index', and 'find', and 'mirrors',
and etc. Added 'extra_args' which are passed onto pip.
The use case for --index-url is having a private pypi repo, like
http://pypi.python.org/pypi/localshop, to which you publish private
packages. I'm sure most every pip option has a use case for someone.
extra_args handles all those. Can reserve ansible command parameters for
the most common.
Tested with pip 1.1.
2012-12-12 22:40:25 +01:00
|
|
|
argument_spec=dict(
|
|
|
|
state=dict(default='present', choices=state_map.keys()),
|
|
|
|
name=dict(default=None, required=False),
|
|
|
|
version=dict(default=None, required=False),
|
|
|
|
requirements=dict(default=None, required=False),
|
|
|
|
virtualenv=dict(default=None, required=False),
|
2013-02-23 22:56:45 +01:00
|
|
|
virtualenv_site_packages=dict(default='no', type='bool'),
|
2013-02-20 14:52:02 +01:00
|
|
|
virtualenv_command=dict(default='virtualenv', required=False),
|
2013-02-23 22:56:45 +01:00
|
|
|
use_mirrors=dict(default='yes', type='bool'),
|
pip module improvements
- Do not silently ignore malformed pip requirements files.
- Properly reports changed when removing packages.
- "latest" i.e. --upgrade is *not* incompatible with requirements files.
- Less branchy, simpler logic.
- Removed pointless variable "initializations", Python doesn't need that.
Other code simplifications.
- Fun fact; pip install is (kind of) case insensitive, pip freeze is not.
So, 'sqlalchemy' will be reported as installed by install, but missing
by freeze.
The perhaps controversial change and the one that led to finding /
fixing above issues...
Instead of adding command parameters 'index', and 'find', and 'mirrors',
and etc. Added 'extra_args' which are passed onto pip.
The use case for --index-url is having a private pypi repo, like
http://pypi.python.org/pypi/localshop, to which you publish private
packages. I'm sure most every pip option has a use case for someone.
extra_args handles all those. Can reserve ansible command parameters for
the most common.
Tested with pip 1.1.
2012-12-12 22:40:25 +01:00
|
|
|
extra_args=dict(default=None, required=False),
|
|
|
|
),
|
|
|
|
required_one_of=[['name', 'requirements']],
|
|
|
|
mutually_exclusive=[['name', 'requirements']],
|
2013-02-27 21:23:35 +01:00
|
|
|
supports_check_mode=True
|
2012-08-12 00:13:29 +02:00
|
|
|
)
|
2012-08-07 22:38:04 +02:00
|
|
|
|
|
|
|
state = module.params['state']
|
|
|
|
name = module.params['name']
|
|
|
|
version = module.params['version']
|
|
|
|
requirements = module.params['requirements']
|
2013-02-23 19:59:52 +01:00
|
|
|
use_mirrors = module.params['use_mirrors']
|
pip module improvements
- Do not silently ignore malformed pip requirements files.
- Properly reports changed when removing packages.
- "latest" i.e. --upgrade is *not* incompatible with requirements files.
- Less branchy, simpler logic.
- Removed pointless variable "initializations", Python doesn't need that.
Other code simplifications.
- Fun fact; pip install is (kind of) case insensitive, pip freeze is not.
So, 'sqlalchemy' will be reported as installed by install, but missing
by freeze.
The perhaps controversial change and the one that led to finding /
fixing above issues...
Instead of adding command parameters 'index', and 'find', and 'mirrors',
and etc. Added 'extra_args' which are passed onto pip.
The use case for --index-url is having a private pypi repo, like
http://pypi.python.org/pypi/localshop, to which you publish private
packages. I'm sure most every pip option has a use case for someone.
extra_args handles all those. Can reserve ansible command parameters for
the most common.
Tested with pip 1.1.
2012-12-12 22:40:25 +01:00
|
|
|
extra_args = module.params['extra_args']
|
2012-08-07 22:38:04 +02:00
|
|
|
|
|
|
|
if state == 'latest' and version is not None:
|
2012-08-12 00:13:29 +02:00
|
|
|
module.fail_json(msg='version is incompatible with state=latest')
|
pip module improvements
- Do not silently ignore malformed pip requirements files.
- Properly reports changed when removing packages.
- "latest" i.e. --upgrade is *not* incompatible with requirements files.
- Less branchy, simpler logic.
- Removed pointless variable "initializations", Python doesn't need that.
Other code simplifications.
- Fun fact; pip install is (kind of) case insensitive, pip freeze is not.
So, 'sqlalchemy' will be reported as installed by install, but missing
by freeze.
The perhaps controversial change and the one that led to finding /
fixing above issues...
Instead of adding command parameters 'index', and 'find', and 'mirrors',
and etc. Added 'extra_args' which are passed onto pip.
The use case for --index-url is having a private pypi repo, like
http://pypi.python.org/pypi/localshop, to which you publish private
packages. I'm sure most every pip option has a use case for someone.
extra_args handles all those. Can reserve ansible command parameters for
the most common.
Tested with pip 1.1.
2012-12-12 22:40:25 +01:00
|
|
|
if name and '=' in name:
|
|
|
|
module.fail_json(msg='version must be specified in the version parameter')
|
2012-08-07 22:38:04 +02:00
|
|
|
|
pip module improvements
- Do not silently ignore malformed pip requirements files.
- Properly reports changed when removing packages.
- "latest" i.e. --upgrade is *not* incompatible with requirements files.
- Less branchy, simpler logic.
- Removed pointless variable "initializations", Python doesn't need that.
Other code simplifications.
- Fun fact; pip install is (kind of) case insensitive, pip freeze is not.
So, 'sqlalchemy' will be reported as installed by install, but missing
by freeze.
The perhaps controversial change and the one that led to finding /
fixing above issues...
Instead of adding command parameters 'index', and 'find', and 'mirrors',
and etc. Added 'extra_args' which are passed onto pip.
The use case for --index-url is having a private pypi repo, like
http://pypi.python.org/pypi/localshop, to which you publish private
packages. I'm sure most every pip option has a use case for someone.
extra_args handles all those. Can reserve ansible command parameters for
the most common.
Tested with pip 1.1.
2012-12-12 22:40:25 +01:00
|
|
|
err = ''
|
|
|
|
out = ''
|
2012-08-07 22:38:04 +02:00
|
|
|
|
pip module improvements
- Do not silently ignore malformed pip requirements files.
- Properly reports changed when removing packages.
- "latest" i.e. --upgrade is *not* incompatible with requirements files.
- Less branchy, simpler logic.
- Removed pointless variable "initializations", Python doesn't need that.
Other code simplifications.
- Fun fact; pip install is (kind of) case insensitive, pip freeze is not.
So, 'sqlalchemy' will be reported as installed by install, but missing
by freeze.
The perhaps controversial change and the one that led to finding /
fixing above issues...
Instead of adding command parameters 'index', and 'find', and 'mirrors',
and etc. Added 'extra_args' which are passed onto pip.
The use case for --index-url is having a private pypi repo, like
http://pypi.python.org/pypi/localshop, to which you publish private
packages. I'm sure most every pip option has a use case for someone.
extra_args handles all those. Can reserve ansible command parameters for
the most common.
Tested with pip 1.1.
2012-12-12 22:40:25 +01:00
|
|
|
env = module.params['virtualenv']
|
2013-02-20 14:52:02 +01:00
|
|
|
virtualenv_command = module.params['virtualenv_command']
|
2012-08-07 22:38:04 +02:00
|
|
|
|
pip module improvements
- Do not silently ignore malformed pip requirements files.
- Properly reports changed when removing packages.
- "latest" i.e. --upgrade is *not* incompatible with requirements files.
- Less branchy, simpler logic.
- Removed pointless variable "initializations", Python doesn't need that.
Other code simplifications.
- Fun fact; pip install is (kind of) case insensitive, pip freeze is not.
So, 'sqlalchemy' will be reported as installed by install, but missing
by freeze.
The perhaps controversial change and the one that led to finding /
fixing above issues...
Instead of adding command parameters 'index', and 'find', and 'mirrors',
and etc. Added 'extra_args' which are passed onto pip.
The use case for --index-url is having a private pypi repo, like
http://pypi.python.org/pypi/localshop, to which you publish private
packages. I'm sure most every pip option has a use case for someone.
extra_args handles all those. Can reserve ansible command parameters for
the most common.
Tested with pip 1.1.
2012-12-12 22:40:25 +01:00
|
|
|
if env:
|
2013-03-14 04:58:04 +01:00
|
|
|
env = os.path.expanduser(env)
|
2013-02-20 14:52:02 +01:00
|
|
|
virtualenv = module.get_bin_path(virtualenv_command, True)
|
pip module improvements
- Do not silently ignore malformed pip requirements files.
- Properly reports changed when removing packages.
- "latest" i.e. --upgrade is *not* incompatible with requirements files.
- Less branchy, simpler logic.
- Removed pointless variable "initializations", Python doesn't need that.
Other code simplifications.
- Fun fact; pip install is (kind of) case insensitive, pip freeze is not.
So, 'sqlalchemy' will be reported as installed by install, but missing
by freeze.
The perhaps controversial change and the one that led to finding /
fixing above issues...
Instead of adding command parameters 'index', and 'find', and 'mirrors',
and etc. Added 'extra_args' which are passed onto pip.
The use case for --index-url is having a private pypi repo, like
http://pypi.python.org/pypi/localshop, to which you publish private
packages. I'm sure most every pip option has a use case for someone.
extra_args handles all those. Can reserve ansible command parameters for
the most common.
Tested with pip 1.1.
2012-12-12 22:40:25 +01:00
|
|
|
if not os.path.exists(os.path.join(env, 'bin', 'activate')):
|
2013-02-27 21:23:35 +01:00
|
|
|
if module.check_mode:
|
|
|
|
module.exit_json(changed=True)
|
2013-02-23 19:59:52 +01:00
|
|
|
if module.params['virtualenv_site_packages']:
|
2013-01-29 18:30:09 +01:00
|
|
|
cmd = '%s --system-site-packages %s' % (virtualenv, env)
|
|
|
|
else:
|
|
|
|
cmd = '%s %s' % (virtualenv, env)
|
Update modules to use run_command in module_common.py
This updates apt, apt_repository, command, cron, easy_install, facter,
fireball, git, group, mount, ohai, pip, service, setup, subversion,
supervisorctl, svr4pkg, user, and yum to take advantage of run_command
in module_common.py.
2013-01-12 07:10:21 +01:00
|
|
|
rc, out_venv, err_venv = module.run_command(cmd)
|
pip module improvements
- Do not silently ignore malformed pip requirements files.
- Properly reports changed when removing packages.
- "latest" i.e. --upgrade is *not* incompatible with requirements files.
- Less branchy, simpler logic.
- Removed pointless variable "initializations", Python doesn't need that.
Other code simplifications.
- Fun fact; pip install is (kind of) case insensitive, pip freeze is not.
So, 'sqlalchemy' will be reported as installed by install, but missing
by freeze.
The perhaps controversial change and the one that led to finding /
fixing above issues...
Instead of adding command parameters 'index', and 'find', and 'mirrors',
and etc. Added 'extra_args' which are passed onto pip.
The use case for --index-url is having a private pypi repo, like
http://pypi.python.org/pypi/localshop, to which you publish private
packages. I'm sure most every pip option has a use case for someone.
extra_args handles all those. Can reserve ansible command parameters for
the most common.
Tested with pip 1.1.
2012-12-12 22:40:25 +01:00
|
|
|
out += out_venv
|
|
|
|
err += err_venv
|
|
|
|
if rc != 0:
|
|
|
|
_fail(module, cmd, out, err)
|
|
|
|
|
|
|
|
pip = _get_pip(module, env)
|
|
|
|
|
|
|
|
cmd = '%s %s' % (pip, state_map[state])
|
|
|
|
if state != 'absent' and use_mirrors:
|
|
|
|
cmd += ' --use-mirrors'
|
|
|
|
if extra_args:
|
|
|
|
cmd += ' %s' % extra_args
|
|
|
|
if name:
|
|
|
|
cmd += ' %s' % _get_full_name(name, version)
|
|
|
|
elif requirements:
|
|
|
|
cmd += ' -r %s' % requirements
|
2012-08-07 22:38:04 +02:00
|
|
|
|
2013-02-27 21:23:35 +01:00
|
|
|
if module.check_mode:
|
|
|
|
module.exit_json(changed=True)
|
2013-03-15 23:05:21 +01:00
|
|
|
os.chdir(tempfile.gettempdir())
|
Update modules to use run_command in module_common.py
This updates apt, apt_repository, command, cron, easy_install, facter,
fireball, git, group, mount, ohai, pip, service, setup, subversion,
supervisorctl, svr4pkg, user, and yum to take advantage of run_command
in module_common.py.
2013-01-12 07:10:21 +01:00
|
|
|
rc, out_pip, err_pip = module.run_command(cmd)
|
pip module improvements
- Do not silently ignore malformed pip requirements files.
- Properly reports changed when removing packages.
- "latest" i.e. --upgrade is *not* incompatible with requirements files.
- Less branchy, simpler logic.
- Removed pointless variable "initializations", Python doesn't need that.
Other code simplifications.
- Fun fact; pip install is (kind of) case insensitive, pip freeze is not.
So, 'sqlalchemy' will be reported as installed by install, but missing
by freeze.
The perhaps controversial change and the one that led to finding /
fixing above issues...
Instead of adding command parameters 'index', and 'find', and 'mirrors',
and etc. Added 'extra_args' which are passed onto pip.
The use case for --index-url is having a private pypi repo, like
http://pypi.python.org/pypi/localshop, to which you publish private
packages. I'm sure most every pip option has a use case for someone.
extra_args handles all those. Can reserve ansible command parameters for
the most common.
Tested with pip 1.1.
2012-12-12 22:40:25 +01:00
|
|
|
out += out_pip
|
|
|
|
err += err_pip
|
|
|
|
if rc == 1 and state == 'absent' and 'not installed' in out_pip:
|
|
|
|
pass # rc is 1 when attempting to uninstall non-installed package
|
|
|
|
elif rc != 0:
|
|
|
|
_fail(module, cmd, out, err)
|
2012-08-07 22:38:04 +02:00
|
|
|
|
pip module improvements
- Do not silently ignore malformed pip requirements files.
- Properly reports changed when removing packages.
- "latest" i.e. --upgrade is *not* incompatible with requirements files.
- Less branchy, simpler logic.
- Removed pointless variable "initializations", Python doesn't need that.
Other code simplifications.
- Fun fact; pip install is (kind of) case insensitive, pip freeze is not.
So, 'sqlalchemy' will be reported as installed by install, but missing
by freeze.
The perhaps controversial change and the one that led to finding /
fixing above issues...
Instead of adding command parameters 'index', and 'find', and 'mirrors',
and etc. Added 'extra_args' which are passed onto pip.
The use case for --index-url is having a private pypi repo, like
http://pypi.python.org/pypi/localshop, to which you publish private
packages. I'm sure most every pip option has a use case for someone.
extra_args handles all those. Can reserve ansible command parameters for
the most common.
Tested with pip 1.1.
2012-12-12 22:40:25 +01:00
|
|
|
if state == 'absent':
|
|
|
|
changed = 'Successfully uninstalled' in out_pip
|
|
|
|
else:
|
2012-08-07 22:38:04 +02:00
|
|
|
changed = 'Successfully installed' in out_pip
|
|
|
|
|
|
|
|
module.exit_json(changed=changed, cmd=cmd, name=name, version=version,
|
2013-03-14 03:25:58 +01:00
|
|
|
state=state, requirements=requirements, virtualenv=env, stdout=out, stderr=err)
|
2012-08-07 22:38:04 +02:00
|
|
|
|
|
|
|
# this is magic, see lib/ansible/module_common.py
|
|
|
|
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
|
|
|
|
|
|
|
|
main()
|