From 1fc4e0d40969447310a366d09e408de664fb4972 Mon Sep 17 00:00:00 2001 From: Derek Vanderveer Date: Sun, 15 Jun 2025 15:21:00 -0400 Subject: [PATCH 01/11] redhat_subscription: skip attach if OS does not support it --- plugins/modules/redhat_subscription.py | 28 ++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/plugins/modules/redhat_subscription.py b/plugins/modules/redhat_subscription.py index 6818253c9d..458ebb36bc 100644 --- a/plugins/modules/redhat_subscription.py +++ b/plugins/modules/redhat_subscription.py @@ -116,6 +116,7 @@ options: description: - Upon successful registration, auto-consume available subscriptions. - Please note that the alias O(ignore:autosubscribe) was removed in community.general 9.0.0. + - Also note that this option does nothing for RHEL 10+ and Fedora 41+, where the attach option has been removed. type: bool activationkey: description: @@ -446,6 +447,29 @@ class Rhsm(object): consumer_name, consumer_id, force_register, environment, release) + def _has_attach_command(self): + """ + Checks whether subscription-manager has an attach command. + + :returns: bool -- whether subscription-manager has an attach command. + """ + + def str2int(s, default=0): + try: + return int(s) + except ValueError: + return default + + distro_id = distro.id() + 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 == 'fedora' and distro_version[0] >= 41: + return False + if distro_id == 'rhel' and distro_version[0] >= 10: + return False + return True + def _register_using_cli(self, username, password, token, auto_attach, activationkey, org_id, consumer_type, consumer_name, consumer_id, force_register, environment, release): @@ -464,7 +488,7 @@ class Rhsm(object): if org_id: args.extend(['--org', org_id]) - if auto_attach: + if auto_attach and self._has_attach_command(): args.append('--auto-attach') if consumer_type: @@ -736,7 +760,7 @@ class Rhsm(object): self.module.run_command([SUBMAN_CMD, 'refresh'], check_rc=True, expand_user_and_vars=False) - if auto_attach: + if auto_attach and self._has_attach_command(): args = [SUBMAN_CMD, 'attach', '--auto'] self.module.run_command(args, check_rc=True, expand_user_and_vars=False) From 2af288e8b5c2eac7d2eec132c24e581def576294 Mon Sep 17 00:00:00 2001 From: Derek Vanderveer Date: Sun, 15 Jun 2025 15:37:31 -0400 Subject: [PATCH 02/11] add changelog fragment --- changelogs/fragments/10253-redhat_subscription-attach.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100755 changelogs/fragments/10253-redhat_subscription-attach.yml diff --git a/changelogs/fragments/10253-redhat_subscription-attach.yml b/changelogs/fragments/10253-redhat_subscription-attach.yml new file mode 100755 index 0000000000..4eda2fab75 --- /dev/null +++ b/changelogs/fragments/10253-redhat_subscription-attach.yml @@ -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) From 21c0e58a6e226f6d726f9ad3959896e6f1794988 Mon Sep 17 00:00:00 2001 From: Derek Vanderveer Date: Sun, 15 Jun 2025 16:10:54 -0400 Subject: [PATCH 03/11] fix file mode of changelog fragment --- changelogs/fragments/10253-redhat_subscription-attach.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 changelogs/fragments/10253-redhat_subscription-attach.yml diff --git a/changelogs/fragments/10253-redhat_subscription-attach.yml b/changelogs/fragments/10253-redhat_subscription-attach.yml old mode 100755 new mode 100644 From 32584e4b5af81cc1ac53bae928875d918632aefb Mon Sep 17 00:00:00 2001 From: Derek Vanderveer Date: Mon, 16 Jun 2025 13:44:37 -0400 Subject: [PATCH 04/11] skip remove operation if OS does not support it --- plugins/modules/redhat_subscription.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/plugins/modules/redhat_subscription.py b/plugins/modules/redhat_subscription.py index 458ebb36bc..a54fa04733 100644 --- a/plugins/modules/redhat_subscription.py +++ b/plugins/modules/redhat_subscription.py @@ -470,6 +470,15 @@ class Rhsm(object): return False return True + def _has_remove_command(self): + """ + Checks whether subscription-manager has a remove command. + + :returns: bool -- whether subscription-manager has a remove command. + """ + # subscription-manager remove command was removed in Fedora 41 and RHEL 10, same as attach + return self._has_attach_command() + def _register_using_cli(self, username, password, token, auto_attach, activationkey, org_id, consumer_type, consumer_name, consumer_id, force_register, environment, release): @@ -786,7 +795,7 @@ class Rhsm(object): if serials is None: items = ["--all"] - if items: + if items and self._has_remove_command(): args = [SUBMAN_CMD, 'remove'] + items rc, stderr, stdout = self.module.run_command(args, check_rc=True) return serials From 21fc7f6a6e8a47ed90154c6478e0b1041b1c6548 Mon Sep 17 00:00:00 2001 From: Derek Vanderveer Date: Mon, 16 Jun 2025 14:02:40 -0400 Subject: [PATCH 05/11] update changelog fragment --- changelogs/fragments/10253-redhat_subscription-attach.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelogs/fragments/10253-redhat_subscription-attach.yml b/changelogs/fragments/10253-redhat_subscription-attach.yml index 4eda2fab75..c4e9656130 100644 --- a/changelogs/fragments/10253-redhat_subscription-attach.yml +++ b/changelogs/fragments/10253-redhat_subscription-attach.yml @@ -1,2 +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) + - redhat_subscription - skip attach and remove operations for OS versions where these sub-commands have been removed (https://github.com/ansible-collections/community.general/issues/10253, https://github.com/ansible-collections/community.general/issues/10260) From 1075ee10acd5eb3992e1527460b2b7f2a8b1d0c4 Mon Sep 17 00:00:00 2001 From: Derek Vanderveer Date: Tue, 17 Jun 2025 11:38:29 -0400 Subject: [PATCH 06/11] Revert "skip remove operation if OS does not support it" This reverts commit 32584e4b5af81cc1ac53bae928875d918632aefb. --- plugins/modules/redhat_subscription.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/plugins/modules/redhat_subscription.py b/plugins/modules/redhat_subscription.py index a54fa04733..458ebb36bc 100644 --- a/plugins/modules/redhat_subscription.py +++ b/plugins/modules/redhat_subscription.py @@ -470,15 +470,6 @@ class Rhsm(object): return False return True - def _has_remove_command(self): - """ - Checks whether subscription-manager has a remove command. - - :returns: bool -- whether subscription-manager has a remove command. - """ - # subscription-manager remove command was removed in Fedora 41 and RHEL 10, same as attach - return self._has_attach_command() - def _register_using_cli(self, username, password, token, auto_attach, activationkey, org_id, consumer_type, consumer_name, consumer_id, force_register, environment, release): @@ -795,7 +786,7 @@ class Rhsm(object): if serials is None: items = ["--all"] - if items and self._has_remove_command(): + if items: args = [SUBMAN_CMD, 'remove'] + items rc, stderr, stdout = self.module.run_command(args, check_rc=True) return serials From 7a8bab2849e5159edfd6f601c4f2e0c1094507a9 Mon Sep 17 00:00:00 2001 From: Derek Vanderveer Date: Tue, 17 Jun 2025 11:38:33 -0400 Subject: [PATCH 07/11] Revert "update changelog fragment" This reverts commit 21fc7f6a6e8a47ed90154c6478e0b1041b1c6548. --- changelogs/fragments/10253-redhat_subscription-attach.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelogs/fragments/10253-redhat_subscription-attach.yml b/changelogs/fragments/10253-redhat_subscription-attach.yml index c4e9656130..4eda2fab75 100644 --- a/changelogs/fragments/10253-redhat_subscription-attach.yml +++ b/changelogs/fragments/10253-redhat_subscription-attach.yml @@ -1,2 +1,2 @@ bugfixes: - - redhat_subscription - skip attach and remove operations for OS versions where these sub-commands have been removed (https://github.com/ansible-collections/community.general/issues/10253, https://github.com/ansible-collections/community.general/issues/10260) + - 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) From 1c93b7bdce7299697d07b228507df86d9968faf2 Mon Sep 17 00:00:00 2001 From: Derek Vanderveer Date: Tue, 17 Jun 2025 13:11:20 -0400 Subject: [PATCH 08/11] address review feedback --- plugins/modules/redhat_subscription.py | 44 +++++++++++--------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/plugins/modules/redhat_subscription.py b/plugins/modules/redhat_subscription.py index 458ebb36bc..a79b10bd6f 100644 --- a/plugins/modules/redhat_subscription.py +++ b/plugins/modules/redhat_subscription.py @@ -116,7 +116,7 @@ options: description: - Upon successful registration, auto-consume available subscriptions. - Please note that the alias O(ignore:autosubscribe) was removed in community.general 9.0.0. - - Also note that this option does nothing for RHEL 10+ and Fedora 41+, where the attach option has been removed. + - 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: @@ -431,6 +431,21 @@ class Rhsm(object): 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 == 'fedora' and distro_version[0] >= 41) or distro_version[0] >= 10: + 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 @@ -447,29 +462,6 @@ class Rhsm(object): consumer_name, consumer_id, force_register, environment, release) - def _has_attach_command(self): - """ - Checks whether subscription-manager has an attach command. - - :returns: bool -- whether subscription-manager has an attach command. - """ - - def str2int(s, default=0): - try: - return int(s) - except ValueError: - return default - - distro_id = distro.id() - 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 == 'fedora' and distro_version[0] >= 41: - return False - if distro_id == 'rhel' and distro_version[0] >= 10: - return False - return True - def _register_using_cli(self, username, password, token, auto_attach, activationkey, org_id, consumer_type, consumer_name, consumer_id, force_register, environment, release): @@ -488,7 +480,7 @@ class Rhsm(object): if org_id: args.extend(['--org', org_id]) - if auto_attach and self._has_attach_command(): + if auto_attach: args.append('--auto-attach') if consumer_type: @@ -760,7 +752,7 @@ class Rhsm(object): self.module.run_command([SUBMAN_CMD, 'refresh'], check_rc=True, expand_user_and_vars=False) - if auto_attach and self._has_attach_command(): + if auto_attach: args = [SUBMAN_CMD, 'attach', '--auto'] self.module.run_command(args, check_rc=True, expand_user_and_vars=False) From fa1fb34061ac2c9d6275bcf5a7552640fe95d13a Mon Sep 17 00:00:00 2001 From: Derek Vanderveer Date: Tue, 17 Jun 2025 13:54:33 -0400 Subject: [PATCH 09/11] re-add auto_attach distro ID check for RHEL --- plugins/modules/redhat_subscription.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/modules/redhat_subscription.py b/plugins/modules/redhat_subscription.py index a79b10bd6f..684236f5c9 100644 --- a/plugins/modules/redhat_subscription.py +++ b/plugins/modules/redhat_subscription.py @@ -443,7 +443,10 @@ class Rhsm(object): 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 == 'fedora' and distro_version[0] >= 41) or distro_version[0] >= 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 From 84ce3f6027e175625ce39e25911e5b3de26ecdc6 Mon Sep 17 00:00:00 2001 From: Derek Vanderveer Date: Tue, 17 Jun 2025 18:40:44 -0400 Subject: [PATCH 10/11] fix changelog fragment and usage note --- changelogs/fragments/10253-redhat_subscription-attach.yml | 2 +- plugins/modules/redhat_subscription.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/changelogs/fragments/10253-redhat_subscription-attach.yml b/changelogs/fragments/10253-redhat_subscription-attach.yml index 4eda2fab75..4d04b34af2 100644 --- a/changelogs/fragments/10253-redhat_subscription-attach.yml +++ b/changelogs/fragments/10253-redhat_subscription-attach.yml @@ -1,2 +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) + - 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, https://github.com/ansible-collections/community.general/pull/10254) diff --git a/plugins/modules/redhat_subscription.py b/plugins/modules/redhat_subscription.py index 684236f5c9..80d72db84b 100644 --- a/plugins/modules/redhat_subscription.py +++ b/plugins/modules/redhat_subscription.py @@ -116,7 +116,8 @@ options: 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. + - Since community.general 11.1.0 resp. 10.7.2, this option does nothing for RHEL 10+ and Fedora 41+ where + C(attach) has been removed. type: bool activationkey: description: From 5973a4b2790601a38e69cb3239884c9e5c2cd12f Mon Sep 17 00:00:00 2001 From: Derek Vanderveer Date: Wed, 18 Jun 2025 11:52:08 -0400 Subject: [PATCH 11/11] simplify version check for attach --- plugins/modules/redhat_subscription.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/plugins/modules/redhat_subscription.py b/plugins/modules/redhat_subscription.py index 80d72db84b..fd38d4a3bf 100644 --- a/plugins/modules/redhat_subscription.py +++ b/plugins/modules/redhat_subscription.py @@ -432,21 +432,15 @@ class Rhsm(object): 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 + distro_id = distro.id() + try: + distro_major_version = int(distro.major_version()) + except ValueError: + distro_major_version = 0 if ( - (distro_id == 'rhel' and distro_version[0] >= 10) - or (distro_id == 'fedora' and distro_version[0] >= 41) + (distro_id == 'rhel' and distro_major_version >= 10) + or (distro_id == 'fedora' and distro_major_version >= 41) ): auto_attach = False