How do I use subscription-manager in a kickstart file?

Solution Verified - Updated

Environment

  • Red Hat Enterprise Linux 6.1 or higher
  • Red Hat Enterprise Linux 5.7 or higher
  • Red Hat Enterprise Linux 7

Issue

  • I want to be able to use the subscription-manager command to register and subscribe a system from a kickstart file. What are my different options for doing that?

Resolution

Choose from two basic scenarios for using the subscription-manager command in a kickstart file. In both cases, you should:

  • Add commands to the %post section of the kickstart file
  • Identify a log file to see registration results.

SCENARIO 1
Insert subscription-manager after the %post line to register and use --auto-attach to auto subscribe the system. Adding the Red Hat user account name and password (in clear text) lets you subscribe without intervention:

%post --log=/root/registration_results.out
subscription-manager register --auto-attach --username=MY_USER --password=PLAIN_TEXT 

SCENARIO 2
To not expose your Red Hat user name and password to those with access to your kickstart file, use Scenario 2. In this scenario, you must be at the console to manually enter the user name and password when prompted. (This is more secure, but inconvenient.)

%post --log=/root/registration_results.out
# change to new vt and set stout/stdin
exec < /dev/tty6 > /dev/tty6
chvt 6
# run post-install
subscription-manager register --auto-attach
# write/call scripts here
# change back to first vt
chvt 1

NOTE: In RHEL7, Use tty8 since tty6 is used mainly for graphical installation.

In both scenarios, as an alternative to auto subscribing (--auto-attach), you can use:

  • Activation keys (SAM only) or
  • Specific pool IDs

Use activation keys with subscription-manager (only available if you have an on-premise Subscription Asset Manager), as described in This content is not included.Using and Configuring Red Hat Subscription Manager). This also doesn't require a user name and password. For example:

%post --log=/root/registration_results.out
subscription-manager register --org="IT Dept" --activationkey=abcd1234

Use a specific pool ID with subscription-manager to choose the exact subscription to assign to the system. For example:

%post --log=/root/registration_results.out
subscription-manager register --username=jsmith --password=secret
subscription-manager attach --pool=7b64f892219e98de4138711cea132a

Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.