From a45b90e93f46851ca10b37acb883bda270f8e6c9 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Tue, 14 Jun 2022 07:26:38 +0200 Subject: [PATCH] redhat_subscription: call 'remove' instead of 'unsubscribe' (#4809) The 'unsubscribe' command of 'subscription-manager' was deprecated already in subscription-manager 1.11.3, shipped with RHEL 5.11. As it was removed in subscription-manager 1.29.x, unsubscribing from pools was thus broken. The simple fix is to call the proper command, 'remove'. --- .../fragments/4809-redhat_subscription-unsubscribe.yaml | 2 ++ plugins/modules/packaging/os/redhat_subscription.py | 2 +- .../plugins/modules/packaging/os/test_redhat_subscription.py | 5 +++-- 3 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/4809-redhat_subscription-unsubscribe.yaml diff --git a/changelogs/fragments/4809-redhat_subscription-unsubscribe.yaml b/changelogs/fragments/4809-redhat_subscription-unsubscribe.yaml new file mode 100644 index 0000000000..39a364d007 --- /dev/null +++ b/changelogs/fragments/4809-redhat_subscription-unsubscribe.yaml @@ -0,0 +1,2 @@ +bugfixes: + - redhat_subscription - fix unsubscribing on RHEL 9 (https://github.com/ansible-collections/community.general/issues/4741). diff --git a/plugins/modules/packaging/os/redhat_subscription.py b/plugins/modules/packaging/os/redhat_subscription.py index 7bb540b3f1..7309ba7d66 100644 --- a/plugins/modules/packaging/os/redhat_subscription.py +++ b/plugins/modules/packaging/os/redhat_subscription.py @@ -468,7 +468,7 @@ class Rhsm(RegistrationBase): items = ["--all"] if items: - args = [SUBMAN_CMD, 'unsubscribe'] + items + args = [SUBMAN_CMD, 'remove'] + items rc, stderr, stdout = self.module.run_command(args, check_rc=True) return serials diff --git a/tests/unit/plugins/modules/packaging/os/test_redhat_subscription.py b/tests/unit/plugins/modules/packaging/os/test_redhat_subscription.py index 7f430ee72c..8eb7ead674 100644 --- a/tests/unit/plugins/modules/packaging/os/test_redhat_subscription.py +++ b/tests/unit/plugins/modules/packaging/os/test_redhat_subscription.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- # Author: Jiri Hnidek (jhnidek@redhat.com) # # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) @@ -118,7 +119,7 @@ TEST_CASES = [ (0, 'system identity: b26df632-25ed-4452-8f89-0308bfd167cb', '') ), ( - ['/testbin/subscription-manager', 'unsubscribe', '--all'], + ['/testbin/subscription-manager', 'remove', '--all'], {'check_rc': True}, (0, '', '') ), @@ -755,7 +756,7 @@ Entitlement Type: Physical ( [ '/testbin/subscription-manager', - 'unsubscribe', + 'remove', '--serial=7807912223970164816', ], {'check_rc': True},