Use 'pip freeze' output to detect changes with requirement specified
If the requirements contains a repos url it will always report 'Successfully installed'; there is no difference in the output to tell apart if anything new was pulled. Use freeze to detect if the environment changed in any way. Should fix ansible/ansible#1705
This commit is contained in:
parent
a98b807b26
commit
a95fee4079
1 changed files with 11 additions and 1 deletions
|
@ -363,6 +363,12 @@ def main():
|
|||
changed = (state == 'present' and not is_present) or (state == 'absent' and is_present)
|
||||
module.exit_json(changed=changed, cmd=freeze_cmd, stdout=out, stderr=err)
|
||||
|
||||
if requirements:
|
||||
freeze_cmd = '%s freeze' % pip
|
||||
out_freeze_before = module.run_command(freeze_cmd, cwd=chdir)[1]
|
||||
else:
|
||||
out_freeze_before = None
|
||||
|
||||
rc, out_pip, err_pip = module.run_command(cmd, path_prefix=path_prefix, cwd=chdir)
|
||||
out += out_pip
|
||||
err += err_pip
|
||||
|
@ -375,7 +381,11 @@ def main():
|
|||
if state == 'absent':
|
||||
changed = 'Successfully uninstalled' in out_pip
|
||||
else:
|
||||
changed = 'Successfully installed' in out_pip
|
||||
if out_freeze_before is None:
|
||||
changed = 'Successfully installed' in out_pip
|
||||
else:
|
||||
out_freeze_after = module.run_command(freeze_cmd, cwd=chdir)[1]
|
||||
changed = out_freeze_before != out_freeze_after
|
||||
|
||||
module.exit_json(changed=changed, cmd=cmd, name=name, version=version,
|
||||
state=state, requirements=requirements, virtualenv=env,
|
||||
|
|
Loading…
Reference in a new issue