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.

Ansible register a system with Red Hat Subscription-Manager

  • community.general.redhat_subscription
  • Manage registration and subscriptions to RHSM using the subscription-manager command

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

  • 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 registration

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.

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 [email protected]
[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 [email protected]
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 Subscribe to the YouTube channel, Medium, and Website, X (formerly Twitter) to not miss the next episode of the Ansible Pilot.

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]#

code with ❤️ in GitHub

Conclusion

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

Academy

Learn the Ansible automation technology with some real-life examples in my Udemy 300+ Lessons Video Course.

BUY the Complete Udemy 300+ Lessons Video Course

My book Ansible By Examples: 200+ Automation Examples For Linux and Windows System Administrator and DevOps

BUY the Complete PDF BOOK to easily Copy and Paste the 250+ Ansible code

Want to keep this project going? Please donate

Patreon Buy me a Pizza