From fc82d215a67fed191d0320cbd1a55b4ac369116c Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Wed, 3 Aug 2022 18:54:24 +0200 Subject: [PATCH] yum: fix releasever for latest (#78066) (#78242) Fixes #78058 (cherry picked from commit 2bc2153c01beb4305bb639dbbe342dc925ce66e1) --- .../fragments/78058-yum-releasever-latest.yml | 2 ++ lib/ansible/modules/yum.py | 10 +++++----- .../targets/yum/tasks/yuminstallroot.yml | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 changelogs/fragments/78058-yum-releasever-latest.yml diff --git a/changelogs/fragments/78058-yum-releasever-latest.yml b/changelogs/fragments/78058-yum-releasever-latest.yml new file mode 100644 index 00000000000..3700345d3ea --- /dev/null +++ b/changelogs/fragments/78058-yum-releasever-latest.yml @@ -0,0 +1,2 @@ +bugfixes: + - "yum - fix traceback when ``releasever`` is specified with ``latest`` (https://github.com/ansible/ansible/issues/78058)" diff --git a/lib/ansible/modules/yum.py b/lib/ansible/modules/yum.py index a4955adba04..7a1e70210b8 100644 --- a/lib/ansible/modules/yum.py +++ b/lib/ansible/modules/yum.py @@ -1322,7 +1322,7 @@ class YumModule(YumDnf): updates = {} obsoletes = {} update_all = False - cmd = None + cmd = self.yum_basecmd[:] # determine if we're doing an update all if '*' in items: @@ -1341,7 +1341,7 @@ class YumModule(YumDnf): self.module.fail_json(**res) if update_all: - cmd = self.yum_basecmd + ['update'] + cmd.append('update') will_update = set(updates.keys()) will_update_from_other_package = dict() else: @@ -1523,12 +1523,12 @@ class YumModule(YumDnf): cmd.extend(['--releasever=%s' % self.releasever]) # run commands - if cmd: # update all + if update_all: rc, out, err = self.module.run_command(cmd) res['changed'] = True elif self.update_only: if pkgs['update']: - cmd = self.yum_basecmd + ['update'] + pkgs['update'] + cmd += ['update'] + pkgs['update'] locale = get_best_parsable_locale(self.module) lang_env = dict(LANG=locale, LC_ALL=locale, LC_MESSAGES=locale) rc, out, err = self.module.run_command(cmd, environ_update=lang_env) @@ -1539,7 +1539,7 @@ class YumModule(YumDnf): else: rc, out, err = [0, '', ''] elif pkgs['install'] or will_update and not self.update_only: - cmd = self.yum_basecmd + ['install'] + pkgs['install'] + pkgs['update'] + cmd += ['install'] + pkgs['install'] + pkgs['update'] locale = get_best_parsable_locale(self.module) lang_env = dict(LANG=locale, LC_ALL=locale, LC_MESSAGES=locale) rc, out, err = self.module.run_command(cmd, environ_update=lang_env) diff --git a/test/integration/targets/yum/tasks/yuminstallroot.yml b/test/integration/targets/yum/tasks/yuminstallroot.yml index f9bee6f9ae9..bb69151ad70 100644 --- a/test/integration/targets/yum/tasks/yuminstallroot.yml +++ b/test/integration/targets/yum/tasks/yuminstallroot.yml @@ -109,6 +109,25 @@ - "yum_result.rc == 0" - "yum_result.changed" - "rpm_result.rc == 0" + - name: remove python before another test + yum: + name: 'python' + state: absent + installroot: "{{ buildah_mount.stdout }}" + releasever: "{{ buildah_host_releasever.stdout }}" + - name: test yum install of python using releasever with latest + yum: + name: 'python' + state: latest + 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"