Ansible Pilot

Register a system with Red Hat Subscription-Manager - Ansible module redhat_subscription

How to automate the registration of a machine RedHat Enterprise Linux 8 to subscription-manager using the access.redhat.com credential, assign a pool of entitlement, and install some packages.

How to register a system with Red Hat Subscription-Manager with Ansible?

I’m going to show you a live demo and some simple Ansible code. I’m Luca Berton and welcome to today’s episode of Ansible Pilot.

Ansible register a system with Red Hat Subscription-Manager

Today 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

Let 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.

demo

Live demo of how to register a system with Red Hat Subscription-Manager with Ansible playbook

code

---
- name: subscription-manager module demo
  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 demo] ***********************************************************
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 [email protected]
[[email protected] ~]$ sudo su
[[email protected] devops]# cat /etc/redhat-release
Red Hat Enterprise Linux release 8.4 (Ootpa)
[[email protected] 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
[[email protected] devops]# subscription-manager status
+-------------------------------------------+
System Status Details
+-------------------------------------------+
Overall Status: Unknown
System Purpose Status: Unknown
[[email protected] 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:
[[email protected] devops]# subscription-manager list --available --all
This system is not yet registered. Try 'subscription-manager register --help' for more information.
[[email protected] devops]# subscription-manager refresh
This system is not yet registered. Try 'subscription-manager register --help' for more information.
[[email protected] devops]#

after execution

$ ssh [email protected]
Last login: Fri Nov 26 16:09:35 2021 from 192.168.0.103
[[email protected] ~]$ sudo su
[[email protected] 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
[[email protected] 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:
[[email protected] 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
[[email protected] devops]# subscription-manager refresh
All local data refreshed
[[email protected] 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.
[[email protected] 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
[[email protected] devops]#

code with ❤️ in GitHub

Recap

Now you know how to register a system with Red Hat Subscription-Manager with Ansible. Subscribe to the YouTube channel, Medium, Website and Twitter to not miss the next episode of the Ansible Pilot.

Academy

Learn the Ansible automation technology with some real-life examples in my

Want to keep this project going? Please donate

Trustpilot
Follow me

Subscribe not to miss any new releases

November 26, 2021

FREE Top 10 Best Practices

Top 10 Best Practices of Ansible Automation: save time, reduce errors and stress