Skip to content

Commit

Permalink
[PR #9778/203c1ecf backport][stable-10] redhat_registration: use 'ena…
Browse files Browse the repository at this point in the history
…ble_content' D-Bus option when available (#9784)

redhat_registration: use 'enable_content' D-Bus option when available (#9778)

This makes sure that subscription-manager always enables the content for
the system right after the registration.

This is particular important on EL 10+ and Fedora 41+.

(cherry picked from commit 203c1ec)

Co-authored-by: Pino Toscano <ptoscano@redhat.com>
  • Loading branch information
patchback[bot] and ptoscano authored Feb 20, 2025
1 parent f4fca86 commit b2c34d1
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
bugfixes:
- |
redhat_subscription - use the "enable_content" option (when available) when
registering using D-Bus, to ensure that subscription-manager enables the
content on registration; this is particular important on EL 10+ and Fedora
41+
(https://github.com/ansible-collections/community.general/pull/9778).
41 changes: 41 additions & 0 deletions plugins/modules/redhat_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,45 @@ def str2int(s, default=0):
(distro_version[0] == 9 and distro_version[1] >= 2) or
distro_version[0] > 9)):
dbus_force_option_works = True
# We need to use the 'enable_content' D-Bus option to ensure that
# content is enabled; sadly the option is available depending on the
# version of the distro, and also depending on which API/method is used
# for registration.
dbus_has_enable_content_option = False
if activationkey:
def supports_enable_content_for_activation_keys():
# subscription-manager in Fedora >= 41 has the new option.
if distro_id == 'fedora' and distro_version[0] >= 41:
return True
# Assume EL distros here.
if distro_version[0] >= 10:
return True
return False
dbus_has_enable_content_option = supports_enable_content_for_activation_keys()
else:
def supports_enable_content_for_credentials():
# subscription-manager in any supported Fedora version
# has the new option.
if distro_id == 'fedora':
return True
# Check for RHEL 8 >= 8.6, or RHEL >= 9.
if distro_id == 'rhel' and \
((distro_version[0] == 8 and distro_version[1] >= 6) or
distro_version[0] >= 9):
return True
# CentOS: similar checks as for RHEL, with one extra bit:
# if the 2nd part of the version is empty, it means it is
# CentOS Stream, and thus we can assume it has the latest
# version of subscription-manager.
if distro_id == 'centos' and \
((distro_version[0] == 8 and
(distro_version[1] >= 6 or distro_version_parts[1] == '')) or
distro_version[0] >= 9):
return True
# Unknown or old distro: assume it does not support
# the new option.
return False
dbus_has_enable_content_option = supports_enable_content_for_credentials()

if force_register and not dbus_force_option_works and was_registered:
self.unregister()
Expand Down Expand Up @@ -615,6 +654,8 @@ def supports_option_environments():
register_opts[environment_key] = environment
if force_register and dbus_force_option_works and was_registered:
register_opts['force'] = True
if dbus_has_enable_content_option:
register_opts['enable_content'] = "1"
# Wrap it as proper D-Bus dict
register_opts = dbus.Dictionary(register_opts, signature='sv', variant_level=1)

Expand Down

0 comments on commit b2c34d1

Please sign in to comment.