Ansible subscription-manager: Register RHEL with redhat_subscription Module
By Luca Berton · Published 2024-01-01 · Category: installation
How to register RHEL systems with Red Hat Subscription-Manager using Ansible. Automate registration, pool assignment, and package installation with examples.

How to register a system with Red Hat Subscription-Manager with Ansible?
I'm going to show you a live Playbook and some simple Ansible code. I'm Luca Berton and welcome to today's episode of Ansible Pilot.See also: What’s New in Red Hat Ansible Automation Platform 2.6
Ansible register a system with Red Hat Subscription-Manager
• community.general.redhat_subscription • Manage registration and subscriptions to RHSM using the subscription-manager commandToday we're talking about the Ansible module redhat_subscription.
The full name is community.general.redhat_subscription, which means that is part of the collection community.general maintained by the Ansible community
Manage registration and subscriptions to RHSM using the subscription-manager command.
This module is specific for RedHat Enterprise Linux.
Parameters
• state _string_ - present/absent • username _string_ - access.redhat.com or Satellite 6 username • password _string_ - access.redhat.com or Satellite 6 password • auto_attach _boolean_ - no/yes auto-consume available subscriptions • pool_id _list_ - subscription pool IDs to consume • pool _string_ - '^(Red Hat Enterprise Server|Red Hat Virtualization)$' • consumer_id _string_ - resume a previous registrationLet me summarize the main parameters.
The state parameter allows you to specify if you want to add or remove a registration from the target machine.
The username and password allow you to specify the access.redhat.com website credential or Satellite 6 credential.
Once the machine is registered you need to define which subscription to consume.
The auto_attach allows you to auto consume all the available subscriptions for the Machine.
Alternatively you can specify manually the ID in the pool_id list or a text with all the products that you want to add.
Another interesting option is the parameter customer_id to resume a previous registration.
## Playbook
Live Playbook of how to register a system with Red Hat Subscription-Manager with Ansible playbook
code
• subscription-manager.yml---
- name: subscription-manager module Playbook
hosts: all
become: true
vars:
subscription_username: "username"
subscription_password: "password"
tasks:
- name: register with subscription-manager
community.general.redhat_subscription:
state: present
username: "{{ subscription_username }}"
password: "{{ subscription_password }}"
auto_attach: true
execution
$ ansible-playbook -i virtualmachines/demo/inventory register\ RedHat\ subscription/subscription_manager.yml
PLAY [subscription-manager module Playbook] ***********************************************************
TASK [Gathering Facts] ****************************************************************************
ok: [demo.example.com]
TASK [register with subscription-manager] *********************************************************
changed: [demo.example.com]
PLAY RECAP ****************************************************************************************
demo.example.com : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
before execution
$ ssh devops@demo.example.com
[devops@demo ~]$ sudo su
[root@demo devops]# cat /etc/redhat-release
Red Hat Enterprise Linux release 8.4 (Ootpa)
[root@demo devops]# dnf install nfs-utils
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:28:38 ago on Fri 26 Nov 2021 03:38:17 PM UTC.
No match for argument: nfs-utils
Error: Unable to find a match: nfs-utils
[root@demo devops]# subscription-manager status
+-------------------------------------------+
System Status Details
+-------------------------------------------+
Overall Status: Unknown
System Purpose Status: Unknown
[root@demo devops]# subscription-manager list
+-------------------------------------------+
Installed Product Status
+-------------------------------------------+
Product Name: Red Hat Enterprise Linux for x86_64
Product ID: 479
Version: 8.4
Arch: x86_64
Status: Unknown
Status Details:
Starts:
Ends:
[root@demo devops]# subscription-manager list --available --all
This system is not yet registered. Try 'subscription-manager register --help' for more information.
[root@demo devops]# subscription-manager refresh
This system is not yet registered. Try 'subscription-manager register --help' for more information.
[root@demo devops]#
after execution
$ ssh devops@demo.example.com
Last login: Fri Nov 26 16:09:35 2021 from 192.168.0.103
[devops@demo ~]$ sudo su
[root@demo devops]# subscription-manager status
+-------------------------------------------+
System Status Details
+-------------------------------------------+
Overall Status: Disabled
Content Access Mode is set to Simple Content Access. This host has access to content, regardless of subscription status.
System Purpose Status: Disabled
[root@demo devops]# subscription-manager list
+-------------------------------------------+
Installed Product Status
+-------------------------------------------+
Product Name: Red Hat Enterprise Linux for x86_64
Product ID: 479
Version: 8.4
Arch: x86_64
Status: Not subscribed
Status Details:
Starts:
Ends:
[root@demo devops]# subscription-manager list --available --all
+-------------------------------------------+
Available Subscriptions
+-------------------------------------------+
SKU: xxxxxxx
Contract: xxxxxxxx
Pool ID: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Provides Management: No
Available: 100
Suggested: 1
Service Type: L1-L3
Roles:
Service Level: Self-Support
Usage:
Add-ons:
Subscription Type: Standard
Starts: 11/11/2021
Ends: 01/10/2022
Entitlement Type: Physical
Subscription Name: 60 Day Product Trial of Red Hat Ansible Automation Platform, Self-Supported
(100 Managed Nodes)
Provides: dotNET on RHEL Beta (for RHEL Server)
Red Hat Satellite
Red Hat CodeReady Linux Builder for x86_64
Red Hat Ansible Engine
Red Hat Container Images Beta
Red Hat Ansible Automation Platform
Red Hat Enterprise Linux Atomic Host Beta
Red Hat Container Images
Red Hat Enterprise Linux High Availability for x86_64
Red Hat Single Sign-On
dotNET on RHEL (for RHEL Server)
Red Hat CodeReady Linux Builder for x86_64 - Extended Update Support
Red Hat Enterprise Linux Resilient Storage for x86_64 - Extended Update
Support
Red Hat Enterprise Linux High Availability for x86_64 - Extended Update
Support
Red Hat Enterprise Linux Resilient Storage for x86_64
Red Hat Software Collections (for RHEL Server)
Red Hat Satellite Capsule
Red Hat Enterprise Linux Atomic Host
Red Hat Developer Tools (for RHEL Server)
Red Hat Software Collections Beta (for RHEL Server)
Red Hat Enterprise Linux Server
Red Hat Developer Tools Beta (for RHEL Server)
Red Hat Enterprise Linux for x86_64
Red Hat Enterprise Linux for x86_64 - Extended Update Support
Red Hat Developer Toolset (for RHEL Server)
SKU: xxxxxxx
Contract: xxxxxxxx
Pool ID: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Provides Management: No
Available: 100
Suggested: 1
Service Type: L1-L3
Roles:
Service Level: Self-Support
Usage:
Add-ons:
Subscription Type: Standard
Starts: 11/19/2021
Ends: 01/18/2022
Entitlement Type: Physical
[root@demo devops]# subscription-manager refresh
All local data refreshed
[root@demo devops]# dnf install nfs-utils
Updating Subscription Management repositories.
Last metadata expiration check: 0:02:31 ago on Fri 26 Nov 2021 04:09:10 PM UTC.
Dependencies resolved.
===================================================================================================
Package Arch Version Repository Size
===================================================================================================
Installing:
nfs-utils x86_64 1:2.3.3-46.el8 rhel-8-for-x86_64-baseos-rpms 500 k
Installing dependencies:
gssproxy x86_64 0.8.0-19.el8 rhel-8-for-x86_64-baseos-rpms 119 k
keyutils x86_64 1.5.10-6.el8 rhel-8-for-x86_64-baseos-rpms 63 k
libverto-libevent x86_64 0.3.0-5.el8 rhel-8-for-x86_64-baseos-rpms 16 k
python3-pyyaml x86_64 3.12-12.el8 rhel-8-for-x86_64-baseos-rpms 193 k
quota x86_64 1:4.04-14.el8 rhel-8-for-x86_64-baseos-rpms 214 k
quota-nls noarch 1:4.04-14.el8 rhel-8-for-x86_64-baseos-rpms 95 k
rpcbind x86_64 1.2.5-8.el8 rhel-8-for-x86_64-baseos-rpms 70 k
Transaction Summary
===================================================================================================
Install 8 Packages
Total download size: 1.2 M
Installed size: 3.7 M
Is this ok [y/N]: n
Operation aborted.
[root@demo devops]# subscription-manager status
+-------------------------------------------+
System Status Details
+-------------------------------------------+
Overall Status: Disabled
Content Access Mode is set to Simple Content Access. This host has access to content, regardless of subscription status.
System Purpose Status: Disabled
[root@demo devops]#
See also: Red Hat Ansible Automation Platform 2.4 Released: Key Features and Enhancements
Conclusion
Now you know how to register a system with Red Hat Subscription-Manager with Ansible.
Related Articles
• Ansible become guide • static and dynamic Ansible inventory • building reusable Ansible rolesCategory: installation
Watch the video: Ansible subscription-manager: Register RHEL with redhat_subscription Module — Video Tutorial