Skip to content

Skip attach operation for OS versions that no longer support attach #10254

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
2 changes: 2 additions & 0 deletions changelogs/fragments/10253-redhat_subscription-attach.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- redhat_subscription - skip attach operation for OS versions where the attach sub-command has been removed (https://github.com/ansible-collections/community.general/issues/10253)
19 changes: 19 additions & 0 deletions plugins/modules/redhat_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
description:
- Upon successful registration, auto-consume available subscriptions.
- Please note that the alias O(ignore:autosubscribe) was removed in community.general 9.0.0.
- Since community.general X.Y.Z, this option does nothing for RHEL 10+ and Fedora 41+ where attach has been removed.
type: bool
activationkey:
description:
Expand Down Expand Up @@ -430,6 +431,24 @@ def register(self, was_registered, username, password, token, auto_attach, activ
Raises:
* Exception - if any error occurs during the registration
'''

def str2int(s, default=0):
try:
return int(s)
except ValueError:
return default

distro_id = distro.id()
distro_version_parts = distro.version_parts()
distro_version = tuple(str2int(p) for p in distro_version_parts)

# subscription-manager attach command was removed in Fedora 41 and RHEL 10
if (
(distro_id == 'rhel' and distro_version[0] >= 10)
or (distro_id == 'fedora' and distro_version[0] >= 41)
):
auto_attach = False

# There is no support for token-based registration in the D-Bus API
# of rhsm, so always use the CLI in that case;
# also, since the specified environments are names, and the D-Bus APIs
Expand Down