Merge pull request #1383 from schlueter/add-state-to-easy_install
Add state to easy_install
This commit is contained in:
commit
0877aae3fe
1 changed files with 19 additions and 4 deletions
|
@ -70,6 +70,13 @@ options:
|
||||||
version_added: "1.3"
|
version_added: "1.3"
|
||||||
required: false
|
required: false
|
||||||
default: null
|
default: null
|
||||||
|
state:
|
||||||
|
version_added: "2.0"
|
||||||
|
description:
|
||||||
|
- The desired state of the library. C(latest) ensures that the latest version is installed.
|
||||||
|
required: false
|
||||||
|
choices: [present, latest]
|
||||||
|
default: present
|
||||||
notes:
|
notes:
|
||||||
- Please note that the M(easy_install) module can only install Python
|
- Please note that the M(easy_install) module can only install Python
|
||||||
libraries. Thus this module is not able to remove libraries. It is
|
libraries. Thus this module is not able to remove libraries. It is
|
||||||
|
@ -83,14 +90,15 @@ author: Matt Wright
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
# Examples from Ansible Playbooks
|
# Examples from Ansible Playbooks
|
||||||
- easy_install: name=pip
|
- easy_install: name=pip state=latest
|
||||||
|
|
||||||
# Install Bottle into the specified virtualenv.
|
# Install Bottle into the specified virtualenv.
|
||||||
- easy_install: name=bottle virtualenv=/webapps/myapp/venv
|
- easy_install: name=bottle virtualenv=/webapps/myapp/venv
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def _is_package_installed(module, name, easy_install):
|
def _is_package_installed(module, name, easy_install, executable_arguments):
|
||||||
cmd = '%s --dry-run %s' % (easy_install, name)
|
executable_arguments = executable_arguments + ['--dry-run']
|
||||||
|
cmd = '%s %s %s' % (easy_install, ' '.join(executable_arguments), name)
|
||||||
rc, status_stdout, status_stderr = module.run_command(cmd)
|
rc, status_stdout, status_stderr = module.run_command(cmd)
|
||||||
return not ('Reading' in status_stdout or 'Downloading' in status_stdout)
|
return not ('Reading' in status_stdout or 'Downloading' in status_stdout)
|
||||||
|
|
||||||
|
@ -124,6 +132,10 @@ def _get_easy_install(module, env=None, executable=None):
|
||||||
def main():
|
def main():
|
||||||
arg_spec = dict(
|
arg_spec = dict(
|
||||||
name=dict(required=True),
|
name=dict(required=True),
|
||||||
|
state=dict(required=False,
|
||||||
|
default='present',
|
||||||
|
choices=['present','latest'],
|
||||||
|
type='str'),
|
||||||
virtualenv=dict(default=None, required=False),
|
virtualenv=dict(default=None, required=False),
|
||||||
virtualenv_site_packages=dict(default='no', type='bool'),
|
virtualenv_site_packages=dict(default='no', type='bool'),
|
||||||
virtualenv_command=dict(default='virtualenv', required=False),
|
virtualenv_command=dict(default='virtualenv', required=False),
|
||||||
|
@ -137,6 +149,9 @@ def main():
|
||||||
executable = module.params['executable']
|
executable = module.params['executable']
|
||||||
site_packages = module.params['virtualenv_site_packages']
|
site_packages = module.params['virtualenv_site_packages']
|
||||||
virtualenv_command = module.params['virtualenv_command']
|
virtualenv_command = module.params['virtualenv_command']
|
||||||
|
executable_arguments = []
|
||||||
|
if module.params['state'] == 'latest':
|
||||||
|
executable_arguments.append('--upgrade')
|
||||||
|
|
||||||
rc = 0
|
rc = 0
|
||||||
err = ''
|
err = ''
|
||||||
|
@ -167,7 +182,7 @@ def main():
|
||||||
if not installed:
|
if not installed:
|
||||||
if module.check_mode:
|
if module.check_mode:
|
||||||
module.exit_json(changed=True)
|
module.exit_json(changed=True)
|
||||||
cmd = '%s %s' % (easy_install, name)
|
cmd = '%s %s %s' % (easy_install, ' '.join(executable_arguments), name)
|
||||||
rc_easy_inst, out_easy_inst, err_easy_inst = module.run_command(cmd)
|
rc_easy_inst, out_easy_inst, err_easy_inst = module.run_command(cmd)
|
||||||
|
|
||||||
rc += rc_easy_inst
|
rc += rc_easy_inst
|
||||||
|
|
Loading…
Reference in a new issue