From f0e5f2cad0bce7f38c8c2f704bd3b5674669bafe Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Wed, 22 May 2019 20:41:13 +0200 Subject: [PATCH] 2.8: Move update_cache to after self.yum_baseurl definition (#56613) (#56705) * Move update_cache to after self.yum_baseurl definition (#56613) (cherry picked from commit e13566140a5065ce8f603bb3ac04fb0f64a8224d) * Add changelog --- .../fragments/56638-yum-update_cache-fix.yaml | 2 ++ lib/ansible/modules/packaging/os/yum.py | 22 +++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) create mode 100644 changelogs/fragments/56638-yum-update_cache-fix.yaml diff --git a/changelogs/fragments/56638-yum-update_cache-fix.yaml b/changelogs/fragments/56638-yum-update_cache-fix.yaml new file mode 100644 index 00000000000..87c750c9758 --- /dev/null +++ b/changelogs/fragments/56638-yum-update_cache-fix.yaml @@ -0,0 +1,2 @@ +bugfixes: + - yum - fix failure when using ``update_cache`` standalone (https://github.com/ansible/ansible/issues/56638) diff --git a/lib/ansible/modules/packaging/os/yum.py b/lib/ansible/modules/packaging/os/yum.py index f765538a141..8e706a21b64 100644 --- a/lib/ansible/modules/packaging/os/yum.py +++ b/lib/ansible/modules/packaging/os/yum.py @@ -1494,6 +1494,17 @@ class YumModule(YumDnf): if error_msgs: self.module.fail_json(msg='. '.join(error_msgs)) + # 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. + if self.module.get_bin_path('yum-deprecated'): + yumbin = self.module.get_bin_path('yum-deprecated') + else: + yumbin = self.module.get_bin_path('yum') + + # need debug level 2 to get 'Nothing to do' for groupinstall. + self.yum_basecmd = [yumbin, '-d', '2', '-y'] + 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: @@ -1511,17 +1522,6 @@ class YumModule(YumDnf): 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. - if self.module.get_bin_path('yum-deprecated'): - yumbin = self.module.get_bin_path('yum-deprecated') - else: - yumbin = self.module.get_bin_path('yum') - - # need debug level 2 to get 'Nothing to do' for groupinstall. - self.yum_basecmd = [yumbin, '-d', '2', '-y'] - repoquerybin = self.module.get_bin_path('repoquery', required=False) if self.install_repoquery and not repoquerybin and not self.module.check_mode: