fixed handling of releasever for all known scenarios (#69057)
Signed-off-by: Adam Miller <admiller@redhat.com>
This commit is contained in:
parent
cace616aab
commit
8b30360ca9
3 changed files with 106 additions and 18 deletions
2
changelogs/fragments/67050-yum-releasever.yaml
Normal file
2
changelogs/fragments/67050-yum-releasever.yaml
Normal file
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- yum - fixed the handling of releasever parameter
|
|
@ -605,6 +605,9 @@ class YumModule(YumDnf):
|
|||
r_cmd = ['--enablerepo', ','.join(self.enablerepo)]
|
||||
myrepoq.extend(r_cmd)
|
||||
|
||||
if self.releasever:
|
||||
myrepoq.extend('--releasever=%s' % self.releasever)
|
||||
|
||||
cmd = myrepoq + ["--qf", qf, pkgspec]
|
||||
rc, out, err = self.module.run_command(cmd)
|
||||
if rc == 0:
|
||||
|
@ -642,6 +645,9 @@ class YumModule(YumDnf):
|
|||
r_cmd = ['--enablerepo', ','.join(self.enablerepo)]
|
||||
myrepoq.extend(r_cmd)
|
||||
|
||||
if self.releasever:
|
||||
myrepoq.extend('--releasever=%s' % self.releasever)
|
||||
|
||||
cmd = myrepoq + ["--pkgnarrow=updates", "--qf", qf, pkgspec]
|
||||
rc, out, err = self.module.run_command(cmd)
|
||||
|
||||
|
@ -667,6 +673,9 @@ class YumModule(YumDnf):
|
|||
# situation we need to run `yum -y makecache` which will accept
|
||||
# the key and try again.
|
||||
if 'repomd.xml signature could not be verified' in to_native(e):
|
||||
if self.releasever:
|
||||
self.module.run_command(self.yum_basecmd + ['makecache'] + ['--releasever=%s' % self.releasever])
|
||||
else:
|
||||
self.module.run_command(self.yum_basecmd + ['makecache'])
|
||||
pkgs = self.yum_base.returnPackagesByDep(req_spec) + \
|
||||
self.yum_base.returnInstalledPackagesByDep(req_spec)
|
||||
|
@ -692,6 +701,9 @@ class YumModule(YumDnf):
|
|||
r_cmd = ['--enablerepo', ','.join(self.enablerepo)]
|
||||
myrepoq.extend(r_cmd)
|
||||
|
||||
if self.releasever:
|
||||
myrepoq.extend('--releasever=%s' % self.releasever)
|
||||
|
||||
cmd = myrepoq + ["--qf", qf, "--whatprovides", req_spec]
|
||||
rc, out, err = self.module.run_command(cmd)
|
||||
cmd = myrepoq + ["--qf", qf, req_spec]
|
||||
|
@ -831,6 +843,8 @@ class YumModule(YumDnf):
|
|||
|
||||
def repolist(self, repoq, qf="%{repoid}"):
|
||||
cmd = repoq + ["--qf", qf, "-a"]
|
||||
if self.releasever:
|
||||
cmd.extend(['--releasever=%s' % self.releasever])
|
||||
rc, out, _ = self.module.run_command(cmd)
|
||||
if rc == 0:
|
||||
return set(p for p in out.split('\n') if p.strip())
|
||||
|
@ -872,6 +886,8 @@ class YumModule(YumDnf):
|
|||
|
||||
def exec_install(self, items, action, pkgs, res):
|
||||
cmd = self.yum_basecmd + [action] + pkgs
|
||||
if self.releasever:
|
||||
cmd.extend(['--releasever=%s' % self.releasever])
|
||||
|
||||
if self.module.check_mode:
|
||||
self.module.exit_json(changed=True, results=res['results'], changes=dict(installed=pkgs))
|
||||
|
@ -1120,7 +1136,6 @@ class YumModule(YumDnf):
|
|||
cmd = self.yum_basecmd + ["autoremove"] + pkgs
|
||||
else:
|
||||
cmd = self.yum_basecmd + ["remove"] + pkgs
|
||||
|
||||
rc, out, err = self.module.run_command(cmd)
|
||||
|
||||
res['rc'] = rc
|
||||
|
@ -1159,6 +1174,9 @@ class YumModule(YumDnf):
|
|||
|
||||
def run_check_update(self):
|
||||
# run check-update to see if we have packages pending
|
||||
if self.releasever:
|
||||
rc, out, err = self.module.run_command(self.yum_basecmd + ['check-update'] + ['--releasever=%s' % self.releasever])
|
||||
else:
|
||||
rc, out, err = self.module.run_command(self.yum_basecmd + ['check-update'])
|
||||
return rc, out, err
|
||||
|
||||
|
@ -1197,7 +1215,7 @@ class YumModule(YumDnf):
|
|||
|
||||
if '*' in line or len(line) not in [3, 6] or '.' not in line[0]:
|
||||
continue
|
||||
else:
|
||||
|
||||
pkg, version, repo = line[0], line[1], line[2]
|
||||
name, dist = pkg.rsplit('.', 1)
|
||||
updates.update({name: {'version': version, 'dist': dist, 'repo': repo}})
|
||||
|
@ -1256,7 +1274,7 @@ class YumModule(YumDnf):
|
|||
|
||||
# check if pkgspec is installed (if possible for idempotence)
|
||||
# localpkg
|
||||
elif spec.endswith('.rpm') and '://' not in spec:
|
||||
if spec.endswith('.rpm') and '://' not in spec:
|
||||
if not os.path.exists(spec):
|
||||
res['msg'] += "No RPM file matching '%s' found on system" % spec
|
||||
res['results'].append("No RPM file matching '%s' found on system" % spec)
|
||||
|
@ -1277,7 +1295,7 @@ class YumModule(YumDnf):
|
|||
continue
|
||||
|
||||
# URL
|
||||
elif '://' in spec:
|
||||
if '://' in spec:
|
||||
# download package so that we can check if it's already installed
|
||||
with self.set_env_proxy():
|
||||
package = fetch_file(self.module, spec)
|
||||
|
@ -1294,7 +1312,6 @@ class YumModule(YumDnf):
|
|||
continue
|
||||
|
||||
# dep/pkgname - find it
|
||||
else:
|
||||
if self.is_installed(repoq, spec):
|
||||
pkgs['update'].append(spec)
|
||||
else:
|
||||
|
@ -1378,6 +1395,9 @@ class YumModule(YumDnf):
|
|||
res['changed'] = True
|
||||
return res
|
||||
|
||||
if self.releasever:
|
||||
cmd.extend(['--releasever=%s' % self.releasever])
|
||||
|
||||
# run commands
|
||||
if cmd: # update all
|
||||
rc, out, err = self.module.run_command(cmd)
|
||||
|
@ -1455,6 +1475,9 @@ class YumModule(YumDnf):
|
|||
if self.download_dir:
|
||||
self.yum_basecmd.extend(['--downloaddir=%s' % self.download_dir])
|
||||
|
||||
if self.releasever:
|
||||
self.yum_basecmd.extend(['--releasever=%s' % self.releasever])
|
||||
|
||||
if self.installroot != '/':
|
||||
# do not setup installroot by default, because of error
|
||||
# CRITICAL:yum.cli:Config Error: Error accessing file for config file:////etc/yum.conf
|
||||
|
@ -1582,6 +1605,9 @@ class YumModule(YumDnf):
|
|||
if self.install_repoquery and not repoquerybin and not self.module.check_mode:
|
||||
yum_path = self.module.get_bin_path('yum')
|
||||
if yum_path:
|
||||
if self.releasever:
|
||||
self.module.run_command('%s -y install yum-utils --releasever %s' % (yum_path, self.releasever))
|
||||
else:
|
||||
self.module.run_command('%s -y install yum-utils' % yum_path)
|
||||
repoquerybin = self.module.get_bin_path('repoquery', required=False)
|
||||
|
||||
|
|
|
@ -60,3 +60,63 @@
|
|||
file:
|
||||
path: "{{ yumroot.stdout }}/"
|
||||
state: absent
|
||||
|
||||
# Test for releasever working correctly
|
||||
#
|
||||
# Bugfix: https://github.com/ansible/ansible/issues/67050
|
||||
#
|
||||
# This test case is based on a reproducer originally reported on Reddit:
|
||||
# https://www.reddit.com/r/ansible/comments/g2ps32/ansible_yum_module_throws_up_an_error_when/
|
||||
#
|
||||
# NOTE: For the Ansible upstream CI we can only run this for RHEL7 because the
|
||||
# containerized runtimes in shippable don't allow the nested mounting of
|
||||
# buildah container volumes.
|
||||
- name: perform yuminstallroot in a buildah mount with releasever
|
||||
when:
|
||||
- ansible_facts["distribution_major_version"] == "7"
|
||||
- ansible_facts["distribution"] == "RedHat"
|
||||
block:
|
||||
# Need to enable this RHUI repo for RHEL7 testing in AWS, CentOS has Extras
|
||||
# enabled by default and this is not needed there.
|
||||
- name: enable rhui-rhel-7-server-rhui-extras-rpms repo for RHEL7
|
||||
command: yum-config-manager --enable rhui-rhel-7-server-rhui-extras-rpms
|
||||
- name: update cache to pull repodata
|
||||
yum:
|
||||
update_cache: yes
|
||||
- name: install required packages for buildah test
|
||||
yum:
|
||||
state: present
|
||||
name:
|
||||
- buildah
|
||||
- name: create buildah container from scratch
|
||||
command: "buildah --name yum_installroot_releasever_test from scratch"
|
||||
- name: mount the buildah container
|
||||
command: "buildah mount yum_installroot_releasever_test"
|
||||
register: buildah_mount
|
||||
- name: figure out yum value of $releasever
|
||||
shell: python -c 'import yum; yb = yum.YumBase(); print(yb.conf.yumvar["releasever"])' | tail -1
|
||||
register: buildah_host_releasever
|
||||
- name: test yum install of python using releasever
|
||||
yum:
|
||||
name: 'python'
|
||||
state: present
|
||||
installroot: "{{ buildah_mount.stdout }}"
|
||||
releasever: "{{ buildah_host_releasever.stdout }}"
|
||||
register: yum_result
|
||||
- name: verify installation of python
|
||||
assert:
|
||||
that:
|
||||
- "yum_result.rc == 0"
|
||||
- "yum_result.changed"
|
||||
- "rpm_result.rc == 0"
|
||||
always:
|
||||
- name: remove buildah container
|
||||
command: "buildah rm yum_installroot_releasever_test"
|
||||
ignore_errors: yes
|
||||
- name: remove buildah from CI system
|
||||
yum:
|
||||
state: absent
|
||||
name:
|
||||
- buildah
|
||||
- name: disable rhui-rhel-7-server-rhui-extras-rpms repo for RHEL7
|
||||
command: yum-config-manager --disable rhui-rhel-7-server-rhui-extras-rpms
|
||||
|
|
Loading…
Reference in a new issue