[Want to try out Red Hat Enterprise Linux? Download it now for free.]
An early step in our deployment process for Red Hat Enterprise Linux (RHEL) systems involves registering the system and attaching an appropriate subscription. To automate these two steps, I’m using an Ansible role, which I’d like to share with you.
My environment
In my environment, RHEL runs mainly within different virtualization clusters, and occasionally on dedicated servers (bare metal). We use the following subscriptions for development and production:
- Red Hat Developer Subscription
- Red Hat Enterprise Linux Server, Standard (physical or virtual nodes)
- Red Hat Enterprise Linux for Virtual Datacenters, Standard
The register-rhel-subscription role
My role is minimalistic and has the following structure:
# tree roles/register-rhel-subscription
roles/register-rhel-subscription
|-- defaults
| `-- main.yml
|-- tasks
| `-- main.yml
tasks/main.yml
The Ansible module redhat_subscription manages a system’s registration and subscription with the subscription-manager command. Start by creating your activation key in the Customer Portal. This key enables registration without the need to input the username and password.
Assign this key to the parameter activationkey, like so:
activationkey: "{{ org_activationkey }}"
In the above code, the content of the variable org_activationkey is passed to the parameter. How and where this variable is defined will be explained in the next section.
You also need to add your organization’s ID into org_id. You can find this information with the following:
sudo subscription-manager identity
Then, declares the desired target state through:
state: present
In this case, the system should be registered and a subscription attached. If you change this parameter to state: absent, the system will be unregistered accordingly.
Here is what the code looks like when it’s all put together:
---
# tasks file for register-rhel-subscription
# Register System and add Subcription
- name: Register system and add subscription
redhat_subscription:
activationkey: "{{ org_activationkey }}"
org_id: 1234567
state: present
defaults/main.yml
In this file, we define the default value for the variable org_activationkey:
---
# defaults file for register-rhel-subscription
org_activationkey: "my-datacenter-sub"
The value specified in this file can be overwritten in, for example, host_vars and group_vars (see Using Variables). You can use the group memberships in the Ansible inventory to control which subscription is assigned to a host or to a group of hosts.
Example playbook
With the steps above completed, you can now add the register-rhel-subscription role to your playbook:
---
- hosts: all
tasks:
- name: Group by OS
group_by:
key=os_{{ ansible_distribution }}
changed_when: False
- hosts: os_RedHat
roles: - register-rhel-subscription
Conclusion
So far this solution makes a robust impression, and writing this text took much longer than the actual task. This is a small and simple example of how Ansible could make your Sysadmin Day somewhat easier.
저자 소개
Jörg has been a Sysadmin for over ten years now. His fields of operation include Virtualization (VMware), Linux System Administration and Automation (RHEL), Firewalling (Forcepoint), and Loadbalancing (F5). He is a member of the Red Hat Accelerators Community and author of his personal blog at https://www.my-it-brain.de.
유사한 검색 결과
New efficiency upgrades in Red Hat Advanced Cluster Management for Kubernetes 2.15
Improving VirtOps: Manage, migrate or modernize with Red Hat and Cisco
Technically Speaking | Taming AI agents with observability
Building practical self-healing IT | Technically Speaking
채널별 검색
오토메이션
기술, 팀, 인프라를 위한 IT 자동화 최신 동향
인공지능
고객이 어디서나 AI 워크로드를 실행할 수 있도록 지원하는 플랫폼 업데이트
오픈 하이브리드 클라우드
하이브리드 클라우드로 더욱 유연한 미래를 구축하는 방법을 알아보세요
보안
환경과 기술 전반에 걸쳐 리스크를 감소하는 방법에 대한 최신 정보
엣지 컴퓨팅
엣지에서의 운영을 단순화하는 플랫폼 업데이트
인프라
세계적으로 인정받은 기업용 Linux 플랫폼에 대한 최신 정보
애플리케이션
복잡한 애플리케이션에 대한 솔루션 더 보기
가상화
온프레미스와 클라우드 환경에서 워크로드를 유연하게 운영하기 위한 엔터프라이즈 가상화의 미래