allow pip to take a list of names (#4056)
also simplified argspec by removing defaults
This commit is contained in:
parent
6b4359080e
commit
f874c29dff
1 changed files with 31 additions and 21 deletions
|
@ -36,6 +36,7 @@ options:
|
||||||
name:
|
name:
|
||||||
description:
|
description:
|
||||||
- The name of a Python library to install or the url of the remote package.
|
- The name of a Python library to install or the url of the remote package.
|
||||||
|
- As of 2.2 you can supply a list of names.
|
||||||
required: false
|
required: false
|
||||||
default: null
|
default: null
|
||||||
version:
|
version:
|
||||||
|
@ -270,19 +271,19 @@ def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec=dict(
|
argument_spec=dict(
|
||||||
state=dict(default='present', choices=state_map.keys()),
|
state=dict(default='present', choices=state_map.keys()),
|
||||||
name=dict(default=None, required=False),
|
name=dict(type='list'),
|
||||||
version=dict(default=None, required=False, type='str'),
|
version=dict(type='str'),
|
||||||
requirements=dict(default=None, required=False),
|
requirements=dict(),
|
||||||
virtualenv=dict(default=None, required=False),
|
virtualenv=dict(),
|
||||||
virtualenv_site_packages=dict(default='no', type='bool'),
|
virtualenv_site_packages=dict(default=False, type='bool'),
|
||||||
virtualenv_command=dict(default='virtualenv', required=False),
|
virtualenv_command=dict(default='virtualenv'),
|
||||||
virtualenv_python=dict(default=None, required=False, type='str'),
|
virtualenv_python=dict(type='str'),
|
||||||
use_mirrors=dict(default='yes', type='bool'),
|
use_mirrors=dict(default=True, type='bool'),
|
||||||
extra_args=dict(default=None, required=False),
|
extra_args=dict(),
|
||||||
editable=dict(default='yes', type='bool', required=False),
|
editable=dict(default=True, type='bool'),
|
||||||
chdir=dict(default=None, required=False, type='path'),
|
chdir=dict(type='path'),
|
||||||
executable=dict(default=None, required=False),
|
executable=dict(),
|
||||||
umask=dict(required=False,default=None),
|
umask=dict(),
|
||||||
),
|
),
|
||||||
required_one_of=[['name', 'requirements']],
|
required_one_of=[['name', 'requirements']],
|
||||||
mutually_exclusive=[['name', 'requirements'], ['executable', 'virtualenv']],
|
mutually_exclusive=[['name', 'requirements'], ['executable', 'virtualenv']],
|
||||||
|
@ -366,7 +367,12 @@ def main():
|
||||||
|
|
||||||
# Automatically apply -e option to extra_args when source is a VCS url. VCS
|
# Automatically apply -e option to extra_args when source is a VCS url. VCS
|
||||||
# includes those beginning with svn+, git+, hg+ or bzr+
|
# includes those beginning with svn+, git+, hg+ or bzr+
|
||||||
has_vcs = bool(name and re.match(r'(svn|git|hg|bzr)\+', name))
|
has_vcs = False
|
||||||
|
for pkg in name:
|
||||||
|
if bool(pkg and re.match(r'(svn|git|hg|bzr)\+', pkg)):
|
||||||
|
has_vcs = True
|
||||||
|
break
|
||||||
|
|
||||||
if has_vcs and module.params['editable']:
|
if has_vcs and module.params['editable']:
|
||||||
args_list = [] # used if extra_args is not used at all
|
args_list = [] # used if extra_args is not used at all
|
||||||
if extra_args:
|
if extra_args:
|
||||||
|
@ -378,10 +384,12 @@ def main():
|
||||||
|
|
||||||
if extra_args:
|
if extra_args:
|
||||||
cmd += ' %s' % extra_args
|
cmd += ' %s' % extra_args
|
||||||
if name:
|
|
||||||
cmd += ' %s' % _get_full_name(name, version)
|
for pkg in name:
|
||||||
elif requirements:
|
cmd += ' %s' % _get_full_name(pkg, version)
|
||||||
cmd += ' -r %s' % requirements
|
else:
|
||||||
|
if requirements:
|
||||||
|
cmd += ' -r %s' % requirements
|
||||||
|
|
||||||
|
|
||||||
if module.check_mode:
|
if module.check_mode:
|
||||||
|
@ -400,9 +408,11 @@ def main():
|
||||||
out += out_pip
|
out += out_pip
|
||||||
err += err_pip
|
err += err_pip
|
||||||
|
|
||||||
is_present = _is_present(name, version, out.split())
|
for pkg in name:
|
||||||
|
is_present = _is_present(pkg, version, out.split())
|
||||||
changed = (state == 'present' and not is_present) or (state == 'absent' and is_present)
|
if (state == 'present' and not is_present) or (state == 'absent' and is_present):
|
||||||
|
changed = True
|
||||||
|
break
|
||||||
module.exit_json(changed=changed, cmd=freeze_cmd, stdout=out, stderr=err)
|
module.exit_json(changed=changed, cmd=freeze_cmd, stdout=out, stderr=err)
|
||||||
|
|
||||||
if requirements or has_vcs:
|
if requirements or has_vcs:
|
||||||
|
|
Loading…
Reference in a new issue