allow update_cache as stand alone operation for yum/dnf (#46183)

* allow update_cache as stand alone operation for yum/dnf

Fixes #40068

Signed-off-by: Adam Miller <admiller@redhat.com>

* make sanity tests happy

Signed-off-by: Adam Miller <admiller@redhat.com>
This commit is contained in:
Adam Miller 2018-10-08 07:39:49 -05:00 committed by ansibot
commit c8ed5c29e9
4 changed files with 49 additions and 3 deletions

View file

@ -1461,6 +1461,23 @@ class YumModule(YumDnf):
if error_msgs:
self.module.fail_json(msg='. '.join(error_msgs))
if self.update_cache and not self.names and not self.list:
rc, stdout, stderr = self.module.run_command(self.yum_basecmd + ['clean', 'expire-cache'])
if rc == 0:
self.module.exit_json(
changed=False,
msg="Cache updated",
rc=rc,
results=[]
)
else:
self.module.exit_json(
changed=False,
msg="Failed to update cache",
rc=rc,
results=[stderr],
)
# fedora will redirect yum to dnf, which has incompatibilities
# with how this module expects yum to operate. If yum-deprecated
# is available, use that instead to emulate the old behaviors.