Skip to content
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

redhat_subscription module broken with RHEL 9 #4741

Closed
1 task done
dkolepp opened this issue May 27, 2022 · 7 comments · Fixed by #4809
Closed
1 task done

redhat_subscription module broken with RHEL 9 #4741

dkolepp opened this issue May 27, 2022 · 7 comments · Fixed by #4809
Labels
bug This issue/PR relates to a bug has_pr module module

Comments

@dkolepp
Copy link

dkolepp commented May 27, 2022

Summary

When I try to ensure that a system does not have a subscription active, I get a failed task for a RHEL 9 system.

Example:

- name: Ensure system subscription is absent
  redhat_subscription:
    state: absent
    activationkey: "{{ sat_activationkey }}"
    org_id: "{{ sat_organization }}"

fails for a RHEL9 host.

Issue Type

Bug Report

Component Name

redhat_subscription

Ansible Version

$ ansible --version

Community.general Version

$ ansible-galaxy collection list community.general
Collection        Version
----------------- -------
community.general 5.0.0  

Configuration

$ ansible-config dump --only-changed

OS / Environment

RHEL 9

Steps to Reproduce

- name: Ensure system subscription is absent
  redhat_subscription:
    state: absent
    activationkey: "{{ sat_activationkey }}"
    org_id: "{{ sat_organization }}"

for a RHEL9 host, the task fails:

fatal: [servera]: FAILED! => {"changed": false, "cmd": "/sbin/subscription-manager unsubscribe --all", "msg": "", "rc": 1, "stderr": "", "stderr_lines": [], "stdout": "Usage: subscription-manager MODULE-NAME [MODULE-OPTIONS] [--help]\n\r\nPrimary Modules: \n\n  attach         Attach a specified subscription to the registered system, when system does not use Simple Content Access mode\n  list           List subscription and product information for this system\n  refresh        Pull the latest subscription data from the server\n  register       Register this system to the Customer Portal or another subscription management service\n  release        Configure which operating system release to use\n  remove         Remove all or specific subscriptions from this system\n  status         Show status information for this system's subscriptions and products\n  unregister     Unregister this system from the Customer Portal or another subscription management service\n\nOther Modules:   \n\n  addons         Deprecated, see 'syspurpose'\n  auto-attach    Set if subscriptions are attached on a schedule (default of daily)\n  clean          Remove all local system and subscription data without affecting the server\n  config         List, set, or remove the configuration parameters in use by this system\n  environments   Display the environments available for a user\n  facts          View or update the detected system information\n  identity       Display the identity certificate for this system or request a new one\n  import         Import certificates which were provided outside of the tool\n  orgs           Display the organizations against which a user can register a system\n  plugins        View and configure with 'subscription-manager plugins'\n  redeem         Attempt to redeem a subscription for a preconfigured system\n  repo-override  Manage custom content repository settings\n  repos          List the repositories which this system is entitled to use\n  role           Deprecated, see 'syspurpose'\n  service-level  Deprecated, see 'syspurpose'\n  syspurpose     Convenient module for managing all system purpose settings\n  usage          Deprecated, see 'syspurpose'\n  version        Print version information\n\n", "stdout_lines": ["Usage: subscription-manager MODULE-NAME [MODULE-OPTIONS] [--help]", "", "Primary Modules: ", "", "  attach         Attach a specified subscription to the registered system, when system does not use Simple Content Access mode", "  list           List subscription and product information for this system", "  refresh        Pull the latest subscription data from the server", "  register       Register this system to the Customer Portal or another subscription management service", "  release        Configure which operating system release to use", "  remove         Remove all or specific subscriptions from this system", "  status         Show status information for this system's subscriptions and products", "  unregister     Unregister this system from the Customer Portal or another subscription management service", "", "Other Modules:   ", "", "  addons         Deprecated, see 'syspurpose'", "  auto-attach    Set if subscriptions are attached on a schedule (default of daily)", "  clean          Remove all local system and subscription data without affecting the server", "  config         List, set, or remove the configuration parameters in use by this system", "  environments   Display the environments available for a user", "  facts          View or update the detected system information", "  identity       Display the identity certificate for this system or request a new one", "  import         Import certificates which were provided outside of the tool", "  orgs           Display the organizations against which a user can register a system", "  plugins        View and configure with 'subscription-manager plugins'", "  redeem         Attempt to redeem a subscription for a preconfigured system", "  repo-override  Manage custom content repository settings", "  repos          List the repositories which this system is entitled to use", "  role           Deprecated, see 'syspurpose'", "  service-level  Deprecated, see 'syspurpose'", "  syspurpose     Convenient module for managing all system purpose settings", "  usage          Deprecated, see 'syspurpose'", "  version        Print version information", ""]}

Expected Results

I expected this to unsubscribe the host.

Actual Results

  "stdout_lines": [
    "Usage: subscription-manager MODULE-NAME [MODULE-OPTIONS] [--help]",
    "",
    "Primary Modules: ",
    "",
    "  attach         Attach a specified subscription to the registered system, when system does not use Simple Content Access mode",
    "  list           List subscription and product information for this system",
    "  refresh        Pull the latest subscription data from the server",
    "  register       Register this system to the Customer Portal or another subscription management service",
    "  release        Configure which operating system release to use",
    "  remove         Remove all or specific subscriptions from this system",
    "  status         Show status information for this system's subscriptions and products",
    "  unregister     Unregister this system from the Customer Portal or another subscription management service",
    "",
    "Other Modules:   ",
    "",
    "  addons         Deprecated, see 'syspurpose'",
    "  auto-attach    Set if subscriptions are attached on a schedule (default of daily)",
    "  clean          Remove all local system and subscription data without affecting the server",
    "  config         List, set, or remove the configuration parameters in use by this system",
    "  environments   Display the environments available for a user",
    "  facts          View or update the detected system information",
    "  identity       Display the identity certificate for this system or request a new one",
    "  import         Import certificates which were provided outside of the tool",
    "  orgs           Display the organizations against which a user can register a system",
    "  plugins        View and configure with 'subscription-manager plugins'",
    "  redeem         Attempt to redeem a subscription for a preconfigured system",
    "  repo-override  Manage custom content repository settings",
    "  repos          List the repositories which this system is entitled to use",
    "  role           Deprecated, see 'syspurpose'",
    "  service-level  Deprecated, see 'syspurpose'",
    "  syspurpose     Convenient module for managing all system purpose settings",
    "  usage          Deprecated, see 'syspurpose'",
    "  version        Print version information",
    ""
  ]
}

This appears to happen because in RHEL 9, subscription-manager unsubscribe is not a valid command sequence. There is not unsubscribe sub-command (but there is, in RHEL 8).

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibullbot

This comment was marked as outdated.

@ansibullbot ansibullbot added the bug This issue/PR relates to a bug label May 27, 2022
@ansibullbot
Copy link
Collaborator

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added the module module label May 28, 2022
@kallies
Copy link

kallies commented Jun 3, 2022

subscription-manager unsubscribe was marked as deprecated on RHEL 7 already. I assume the replacement should be

subscription-manager remove --all
subscription-manager unregister

@ptoscano
Copy link
Contributor

ptoscano commented Jun 8, 2022

subscription-manager developer here o/ Thanks for the ticket, I just opened #4809 for fixing this.

@benblasco
Copy link

benblasco commented Jun 12, 2022

Will this change to the module also cover unregistering the host altogether? I see that unsubscribe is replaced with remove according to the linked PR

The description of the state field for the module says:

options:
    state:
        description:
          - whether to register and subscribe (C(present)), or unregister (C(absent)) a system
        choices: [ "present", "absent" ]
        default: "present"
        type: str

As you can see state:absent should also unregister the system altogether, not just remove a subscription or set of subscriptions.

From the subscription-manager docs:
Unregister:

   UNREGISTER OPTIONS
       The  unregister  command removes a system's subscriptions and removes it from the subscription management ser‐
       vice.

       This command has no options.

Remove:

   REMOVE OPTIONS
       The remove command removes a subscription from the system. (This does not uninstall the associated products.)

@ptoscano
Copy link
Contributor

Will this change to the module also cover unregistering the host altogether? I see that unsubscribe is replaced with remove according to the linked PR

The unsubscribe command of subscription-manager(1) has been a deprecated alias for the remove command, at least since RHEL 5.11. They used to do the very same operation, no changes. The issue is that unsubscribe was removed in subscription-manager 1.29.x, thus preventing this Ansible module to do some operations on RHEL 9.x. My PR merely switches to the non-deprecated command, i.e. remove: this is effectively a no-op change for a RHEL 8.x host and earlier, making the module work in RHEL 9.x.

From the subscription-manager docs: Unregister:

I'm not sure why you are looking at the documentation of unregister, which is a different command than unsubscribe/remove.

As you can see state:absent should also unregister the system altogether, not just remove a subscription or set of subscriptions.

Is this the case? If so, that would be a new issue to file, and something already broken before this issue (with my PR).

This was referenced Nov 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug has_pr module module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants