mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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:
parent
960dfa862b
commit
c8ed5c29e9
4 changed files with 49 additions and 3 deletions
3
changelogs/fragments/yumdnf-update-cache.yaml
Normal file
3
changelogs/fragments/yumdnf-update-cache.yaml
Normal file
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
minor_changes:
|
||||
- "yum and dnf can now perform C(update_cache) as a standalone operation for consistency with other package manager modules"
|
|
@ -48,7 +48,7 @@ yumdnf_argument_spec = dict(
|
|||
lock_poll=dict(type='int', default=-1),
|
||||
lock_timeout=dict(type='int', default=10),
|
||||
),
|
||||
required_one_of=[['name', 'list']],
|
||||
required_one_of=[['name', 'list', 'update_cache']],
|
||||
mutually_exclusive=[['name', 'list']],
|
||||
supports_check_mode=True,
|
||||
)
|
||||
|
|
|
@ -576,7 +576,14 @@ class DnfModule(YumDnf):
|
|||
base = dnf.Base()
|
||||
self._configure_base(base, conf_file, disable_gpg_check, installroot)
|
||||
self._specify_repositories(base, disablerepo, enablerepo)
|
||||
base.fill_sack(load_system_repo='auto')
|
||||
try:
|
||||
base.fill_sack(load_system_repo='auto')
|
||||
except dnf.exceptions.RepoError as e:
|
||||
self.module.fail_json(
|
||||
msg="{0}".format(to_text(e)),
|
||||
results=[],
|
||||
rc=1
|
||||
)
|
||||
if self.bugfix:
|
||||
key = {'advisory_type__eq': 'bugfix'}
|
||||
base._update_security_filters = [base.sack.query().filter(**key)]
|
||||
|
@ -584,7 +591,14 @@ class DnfModule(YumDnf):
|
|||
key = {'advisory_type__eq': 'security'}
|
||||
base._update_security_filters = [base.sack.query().filter(**key)]
|
||||
if self.update_cache:
|
||||
base.update_cache()
|
||||
try:
|
||||
base.update_cache()
|
||||
except dnf.exceptions.RepoError as e:
|
||||
self.module.fail_json(
|
||||
msg="{0}".format(to_text(e)),
|
||||
results=[],
|
||||
rc=1
|
||||
)
|
||||
return base
|
||||
|
||||
def list_items(self, command):
|
||||
|
@ -1041,6 +1055,18 @@ class DnfModule(YumDnf):
|
|||
results=[],
|
||||
)
|
||||
|
||||
if self.update_cache and not self.names and not self.list:
|
||||
self.base = self._base(
|
||||
self.conf_file, self.disable_gpg_check, self.disablerepo,
|
||||
self.enablerepo, self.installroot
|
||||
)
|
||||
self.module.exit_json(
|
||||
msg="Cache updated",
|
||||
changed=False,
|
||||
results=[],
|
||||
rc=0
|
||||
)
|
||||
|
||||
# Set state as installed by default
|
||||
# This is not set in AnsibleModule() because the following shouldn't happend
|
||||
# - dnf: autoremove=yes state=installed
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue