Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix yum bug where enablerepo is not honored when disablerepo all #66557

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,2 @@
bugfixes:
- yum - fix bug that caused ``enablerepo`` to not be honored when used with disablerepo all wildcard/glob (https://github.com/ansible/ansible/issues/66549)
11 changes: 6 additions & 5 deletions lib/ansible/modules/packaging/os/yum.py
Expand Up @@ -393,11 +393,11 @@ def __init__(self, module):
self.lockfile = '/var/run/yum.pid'
self._yum_base = None

def _enablerepos_with_error_checking(self, yumbase):
def _enablerepos_with_error_checking(self):
# NOTE: This seems unintuitive, but it mirrors yum's CLI behavior
if len(self.enablerepo) == 1:
try:
yumbase.repos.enableRepo(self.enablerepo[0])
self.yum_base.repos.enableRepo(self.enablerepo[0])
except yum.Errors.YumBaseError as e:
if u'repository not found' in to_text(e):
self.module.fail_json(msg="Repository %s not found." % self.enablerepo[0])
Expand All @@ -406,7 +406,7 @@ def _enablerepos_with_error_checking(self, yumbase):
else:
for rid in self.enablerepo:
try:
yumbase.repos.enableRepo(rid)
self.yum_base.repos.enableRepo(rid)
except yum.Errors.YumBaseError as e:
if u'repository not found' in to_text(e):
self.module.warn("Repository %s not found." % rid)
Expand Down Expand Up @@ -492,10 +492,11 @@ def yum_base(self):
self.yum_base.conf

try:
self._enablerepos_with_error_checking(self._yum_base)

for rid in self.disablerepo:
self.yum_base.repos.disableRepo(rid)

self._enablerepos_with_error_checking()

except Exception as e:
self.module.fail_json(msg="Failure talking to yum: %s" % to_native(e))

Expand Down
19 changes: 19 additions & 0 deletions test/integration/targets/yum/tasks/yum.yml
Expand Up @@ -112,6 +112,25 @@
- "yum_result is not changed"
when: ansible_distribution == 'CentOS'

# This test case is unfortunately distro specific because we have to specify
# repo names which are not the same across Fedora/RHEL/CentOS for base/updates
- name: install sos again with disable all and enable select repo(s)
yum:
name: sos
state: present
enablerepo:
- "base"
- "updates"
disablerepo: "*"
register: yum_result
when: ansible_distribution == 'CentOS'
- name: verify no change on fourth install with missing repo enablerepo (yum)
assert:
that:
- "yum_result is success"
- "yum_result is not changed"
when: ansible_distribution == 'CentOS'

- name: install sos again with only missing repo enablerepo
yum:
name: sos
Expand Down