Add state to easy_install

pull/18777/head
Schlueter 10 years ago committed by Matt Clay
parent 06cd532cc5
commit e198884280

@ -89,8 +89,9 @@ EXAMPLES = '''
- 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.append('--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 +125,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 +142,8 @@ 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 = []
module.params['state'] is 'latest' and executable_arguments.append('--upgrade')
rc = 0 rc = 0
err = '' err = ''
@ -167,7 +174,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…
Cancel
Save