订阅内容

This article was originally published on the Red Hat Customer Portal. The information may no longer be current.

Overview

As a user of subscription-manager, I find myself frequently frustrated when running a subscription-manager list --all --available to find a specific subscription. As I am using an account that has a large number of subscriptions this is painful. And since each subscription has a varying amount of output associated with it, using grep (even with the -A switch) is painful. Ultimately, I end up piping the output via my PAGER (less|more|most) until I find the pool ID that I want. That is less than desirable.

This article covers some new options that are present in newer versions of subscription-manager to make dealing with subscriptions less painful.

Requirements

  • subscription-manager >= 1.13.6-1 (What is included in RHEL >= 6.7 and >= 7.1)
    • Red Hat Subscription Management (RHSM)
    • Red Hat Satellite 6.1 or greater

Features

subscription-manager now has a --matches option which will match a variety of fields, varying with the list type:

  • Installed
    • Product Name
    • Product ID
  • Available
    • Subscription Name
    • Product Name & Product ID for each product listed under Provides:
    • SKU
    • Contract
    • Service Level
  • Consumed
    • Subscription Name
    • Product Name & Product ID for each product listed under Provides
    • SKU
    • Contract
    • Service Level

Let's see it in action:

Use case 1

As a user, I want to find ALL subscriptions which have Red Hat Satellite in their name. (because everyone wants to install Satellite components, right?)

# subscription-manager list --available --matches 'Red Hat Satellite*'

+-------------------------------------------+
    Available Subscriptions
+-------------------------------------------+
Subscription Name:   Red Hat Satellite
Provides:            Red Hat Satellite Capsule Beta
                     Red Hat Beta
                     Red Hat Software Collections (for RHEL Server)
                     Red Hat Satellite Capsule
                     Red Hat Satellite with Embedded Oracle
                     Red Hat Satellite 6 Beta
                     Red Hat Satellite Beta
                     Red Hat Enterprise Linux Server
                     Red Hat Enterprise Linux High Availability (for RHEL Server)
                     Red Hat Satellite
                     Red Hat Software Collections Beta (for RHEL Server)
                     Red Hat Enterprise Linux Load Balancer (for RHEL Server)
SKU:                 MCT0370
Contract:            11223344
Pool ID:             2c918f824e5ef0e8014e675ed46d0eeb
Provides Management: Yes
Available:           1
Suggested:           1
Service Level:       Premium
Service Type:        L1-L3
Subscription Type:   Standard
Ends:                10/08/2016
System Type:         Physical

Subscription Name:   Red Hat Satellite Capsule Server
Provides:            Red Hat Satellite Proxy
                     Red Hat Satellite Capsule Beta
                     Red Hat Beta
                     Red Hat Software Collections (for RHEL Server)
                     Red Hat Satellite Capsule
                     Red Hat Enterprise Linux Server
                     Red Hat Enterprise Linux High Availability (for RHEL Server)
                     Red Hat Software Collections Beta (for RHEL Server)
                     Red Hat Enterprise Linux Load Balancer (for RHEL Server)
SKU:                 MCT0369
Contract:            11223344
Pool ID:             2c918f824e5ef0e8014e675ed2e30e8c
Provides Management: Yes
Available:           5
Suggested:           1
Service Level:       Premium
Service Type:        L1-L3
Subscription Type:   Standard
Ends:                10/08/2016
System Type:         Physical

Use Case 2

As a (more advanced) user, show me all of the RH00004 - Red Hat Enterprise Linux Server, Standard (Physical or Virtual Nodes) subscriptions that I own

#subscription-manager list --available --matches 'RH00004'
+-------------------------------------------+
    Available Subscriptions
+-------------------------------------------+

Subscription Name:   Red Hat Enterprise Linux Server, Standard (Physical or Virtual Nodes)
Provides:            Red Hat Container Images Beta
                     Red Hat Beta
                     Red Hat Software Collections (for RHEL Server)
                     Oracle Java (for RHEL Server)
                     Red Hat Enterprise Linux Atomic Host Beta
                     Red Hat Container Images
                     Red Hat Enterprise Linux Server
                     Red Hat Software Collections Beta (for RHEL Server)
                     Red Hat Enterprise Linux Atomic Host
                     Red Hat Developer Toolset (for RHEL Server)
SKU:                 RH00004
Contract:            11223344
Pool ID:             2c918f824e5ef0e8014e675ed7a10fc2
Provides Management: No
Available:           4
Suggested:           1
Service Level:       Standard
Service Type:        L1-L3
Subscription Type:   Instance Based
Ends:                10/08/2016
System Type:         Physical


Subscription Name:   Red Hat Enterprise Linux Server, Standard (Physical or Virtual Nodes)
Provides:            Red Hat Container Images Beta
                     Red Hat Beta
                     Red Hat Software Collections (for RHEL Server)
                     Oracle Java (for RHEL Server)
                     Red Hat Enterprise Linux Atomic Host Beta
                     Red Hat Container Images
                     Red Hat Enterprise Linux Server
                     Red Hat Software Collections Beta (for RHEL Server)
                     Red Hat Enterprise Linux Atomic Host
                     Red Hat Developer Toolset (for RHEL Server)
SKU:                 RH00004
Contract:            44332211
Pool ID:             2c918f824e5ef0e8014e675ed7320fa2
Provides Management: No
Available:           5
Suggested:           1
Service Level:       Standard
Service Type:        L1-L3
Subscription Type:   Instance Based
Ends:                11/20/2016
System Type:         Physical

Advanced usage 1:

In Satellite 6, when creating a custom product (under Content->Products), a subscription is created, allowing you to treat custom software exactly how you treat Red Hat software. Thus, subscription-manager (and our new handy-dandy --matches command) works for them too.

#  subscription-manager list --available --matches 'Extra*'
+-------------------------------------------+
    Available Subscriptions
+-------------------------------------------+

Subscription Name:   Extra Packages for Enterprise Linux
Provides:
SKU:                 1436175280816
Contract:
Pool ID:             2c918f824e5ef0e8014e62b7abcf0a02
Provides Management: No
Available:           Unlimited
Suggested:           1
Service Level:
Service Type:
Subscription Type:   Standard
Ends:                06/28/2045
System Type:         Physical

Advanced usage 2

I want to search for (and attach) a Satellite Capsule Server subscription. As a review, we can use either '--matches MCT0369' OR '--matches Red Hat Satellite Capsule Server'. Your pick . We'll use the '--pool-only' switch to output just the pool ID and then pipe that to the attach subcommand.

#subscription-manager list --available --matches 'Red Hat Satellite Capsule Server'
+-------------------------------------------+
    Available Subscriptions
+-------------------------------------------+
Subscription Name:   Red Hat Satellite Capsule Server
Provides:            Red Hat Satellite Proxy
                     Red Hat Satellite Capsule Beta
                     Red Hat Beta
                     Red Hat Software Collections (for RHEL Server)
                     Red Hat Satellite Capsule
                     Red Hat Enterprise Linux Server
                     Red Hat Enterprise Linux High Availability (for RHEL Server)
                     Red Hat Software Collections Beta (for RHEL Server)
                     Red Hat Enterprise Linux Load Balancer (for RHEL Server)
SKU:                 MCT0369
Contract:            11223344
Pool ID:             2c918f824e5ef0e8014e675ed2e30e8c
Provides Management: Yes
Available:           5
Suggested:           1
Service Level:       Premium
Service Type:        L1-L3
Subscription Type:   Standard
Ends:                10/08/2015
System Type:         Physical

And let's attach that sub. And there are two ways to do that.

# subscription-manager list --available \
   --matches 'Red Hat Satellite Capsule Server' \
   --pool-only | subscription-manager attach --file=-
Successfully attached a subscription for: Red Hat Satellite Capsule Server

OR

# subscription-manager attach \
  --pool=$(subscription-manager list --available \
  --matches 'Red Hat Satellite Capsule Server' --pool-only)

References

  • man (8) subscription-manager
  • BZ1146125 – [RFE] would like a --contains-text option for subscription-manager list module
  • BZ1210294 - request for subscription-manager to support attaching a matching subscription

关于作者

Rich Jerrido is the Senior Principal Product Manager for Hybrid Cloud Business Services.
 
Read full bio
UI_Icon-Red_Hat-Close-A-Black-RGB

按频道浏览

automation icon

自动化

有关技术、团队和环境 IT 自动化的最新信息

AI icon

人工智能

平台更新使客户可以在任何地方运行人工智能工作负载

open hybrid cloud icon

开放混合云

了解我们如何利用混合云构建更灵活的未来

security icon

安全防护

有关我们如何跨环境和技术减少风险的最新信息

edge icon

边缘计算

简化边缘运维的平台更新

Infrastructure icon

基础架构

全球领先企业 Linux 平台的最新动态

application development icon

应用领域

我们针对最严峻的应用挑战的解决方案

Original series icon

原创节目

关于企业技术领域的创客和领导者们有趣的故事