From b2c34d1afe7919e21bf5d83195f58f8d8af9276a Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Thu, 20 Feb 2025 22:27:03 +0100 Subject: [PATCH] [PR #9778/203c1ecf backport][stable-10] redhat_registration: use 'enable_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 203c1ecfec6e29da8d310fcb79af41b28c6ec342) Co-authored-by: Pino Toscano --- ..._subscription-ensure-to-enable-content.yml | 7 ++++ plugins/modules/redhat_subscription.py | 41 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 changelogs/fragments/9778-redhat_subscription-ensure-to-enable-content.yml diff --git a/changelogs/fragments/9778-redhat_subscription-ensure-to-enable-content.yml b/changelogs/fragments/9778-redhat_subscription-ensure-to-enable-content.yml new file mode 100644 index 00000000000..7163865b6e8 --- /dev/null +++ b/changelogs/fragments/9778-redhat_subscription-ensure-to-enable-content.yml @@ -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). diff --git a/plugins/modules/redhat_subscription.py b/plugins/modules/redhat_subscription.py index 5c91c1ef5f3..6818253c9d9 100644 --- a/plugins/modules/redhat_subscription.py +++ b/plugins/modules/redhat_subscription.py @@ -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() @@ -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)