From 42731ec73f349ead70b4f62b3d9eec4250bc1ffa Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Tue, 12 Mar 2019 18:41:26 +0100 Subject: [PATCH] yum: fix disable_excludes in repoquery fallback (#53552) Fixes #53134 --- lib/ansible/modules/packaging/os/yum.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/ansible/modules/packaging/os/yum.py b/lib/ansible/modules/packaging/os/yum.py index 52d33f275ec..f765538a141 100644 --- a/lib/ansible/modules/packaging/os/yum.py +++ b/lib/ansible/modules/packaging/os/yum.py @@ -1555,6 +1555,23 @@ class YumModule(YumDnf): if self.installroot != '/': repoquery.extend(['--installroot', self.installroot]) + if self.disable_excludes: + # repoquery does not support --disableexcludes, + # so make a temp copy of yum.conf and get rid of the 'exclude=' line there + try: + with open('/etc/yum.conf', 'r') as f: + content = f.readlines() + + tmp_conf_file = tempfile.NamedTemporaryFile(dir=self.module.tmpdir, delete=False) + self.module.add_cleanup_file(tmp_conf_file.name) + + tmp_conf_file.writelines([c for c in content if not c.startswith("exclude=")]) + tmp_conf_file.close() + except Exception as e: + self.module.fail_json(msg="Failure setting up repoquery: %s" % to_native(e)) + + repoquery.extend(['-c', tmp_conf_file.name]) + results = self.ensure(repoquery) if repoquery: results['msg'] = '%s %s' % (