Using the Hammer CLI tool
Administer Satellite or develop custom scripts by using Hammer, the Satellite command-line tool
Abstract
Providing feedback on Red Hat documentation Copy linkLink copied to clipboard!
We appreciate your feedback on our documentation. Let us know how we can improve it.
Use the Create Issue form in Red Hat Jira to provide your feedback. The Jira issue is created in the Red Hat Satellite Jira project, where you can track its progress.
Procedure
- Log in to Atlassian Jira.
- Click the following link: Create Issue.
- Complete the Summary, Description, and Reporter fields. In the Description field, include the documentation URL, chapter or section number, and a detailed description of the issue. Do not modify any other fields in the form.
- Click Create.
Chapter 1. Introduction to Hammer Copy linkLink copied to clipboard!
Hammer is a powerful command-line tool provided with Red Hat Satellite 6. You can use Hammer to configure and manage a Satellite Server either through CLI commands or automation in shell scripts. Hammer also provides an interactive shell.
1.1. Hammer compared to Satellite web UI Copy linkLink copied to clipboard!
Compared to navigating the Satellite web UI, using Hammer can result in much faster interaction with the Satellite Server, as common shell features such as environment variables and aliases are at your disposal. You can also incorporate Hammer commands into reusable scripts for automating tasks of various complexity. Output from Hammer commands can be redirected to other tools, which allows for integration with your existing environment. You can issue Hammer commands directly on the base operating system running Red Hat Satellite.
Access to base operating system on Satellite Server is required to issue Hammer commands, which can limit the number of potential users compared to the Satellite web UI. Although the parity between Hammer and the Satellite web UI is almost complete, the Satellite web UI has development priority and can be ahead especially for newly introduced features.
1.2. Hammer compared to Satellite API Copy linkLink copied to clipboard!
For many tasks, both Hammer and Satellite API are equally applicable. Hammer can be used as a human friendly interface to Satellite API, for example to test responses to API calls before applying them in a script (use the -d option to inspect API calls issued by Hammer, for example hammer -d organization list). Changes in the API are automatically reflected in Hammer, while scripts using the API directly have to be updated manually.
In the background, each Hammer command first establishes a binding to the API, then sends a request. This can have performance implications when executing a large number of Hammer commands in sequence. In contrast, a script communicating directly with the API establishes the binding only once.
For more information, see the Using the Satellite REST API.
1.3. Getting help Copy linkLink copied to clipboard!
View the full list of hammer options and subcommands by executing:
$ hammer --help
Use --help to inspect any subcommand, for example:
$ hammer organization --help
You can search the help output using grep, or redirect it to a text viewer, for example:
$ hammer | less
Chapter 2. Installing standalone Hammer Copy linkLink copied to clipboard!
You can install Hammer on a host running RHEL that has no Satellite Server installed, and use it to connect from the host to a remote Satellite.
Prerequisites
- Ensure that you register the host to Satellite Server or Capsule Server.
Ensure that the following repositories are enabled and synchronized on Satellite Server:
- rhel-9-for-x86_64-baseos-rpms
- rhel-9-for-x86_64-appstream-rpms
- satellite-utils-6.17-for-rhel-9-x86_64-rpms
Procedure
- Enable the required repositories on the host.
Install Hammer CLI:
# dnf install satellite-cliSet the
:host:entry in the/etc/hammer/cli.modules.d/foreman.ymlfile to the Satellite URL::host: 'https://satellite.example.com'
Additional resources
- Enabling repositories on hosts in Managing hosts
- Registering hosts by using global registration in Managing hosts
- Synchronizing Repositories in Managing content
Chapter 3. Hammer authentication Copy linkLink copied to clipboard!
A Satellite user must prove their identity to Red Hat Satellite when entering hammer commands. Hammer commands can be run manually or automatically. In either case, hammer requires Satellite credentials for authentication. There are three methods of hammer authentication:
- Hammer authentication session
- Storing credentials in the hammer configuration file
- Providing credentials with each hammer command
The hammer configuration file method is recommended when running commands automatically. For example, running Satellite maintenance commands from a cron job. When running commands manually, Red Hat recommends using the hammer authentication session and providing credentials with each command.
3.1. Authenticating Hammer using a configuration file Copy linkLink copied to clipboard!
If you ran the Satellite installation with --foreman-initial-admin-username and --foreman-initial-admin-password options, credentials you entered are stored in the ~/.hammer/cli.modules.d/foreman.yml configuration file, and hammer does not prompt for your credentials.
You can also add your credentials to the ~/.hammer/cli.modules.d/foreman.yml configuration file manually:
:foreman:
:username: 'username'
:password: 'password'
Use only spaces for indentation in hammer configuration files, do not use tabs.
If you change your credentials on Satellite Server, you must update the configuration file manually. The installer does not overwrite the configuration file.
3.2. Authenticating Hammer using CLI options Copy linkLink copied to clipboard!
If you do not have your Satellite credentials saved in the ~/.hammer/cli.modules.d/foreman.yml configuration file, hammer prompts you for them each time you enter a command. You can specify your credentials when executing a command as follows:
$ hammer -u username -p password subcommands
Examples in this guide assume that you have saved credentials in the configuration file, or are using a hammer authentication session.
3.3. Authenticating Hammer using sessions Copy linkLink copied to clipboard!
The hammer authentication session is a cache that stores your credentials, and you have to provide them only once, at the beginning of the session. This method is suited to running several hammer commands in succession, for example a script containing hammer commands. In this scenario, you enter your Satellite credentials once, and the script runs as expected. By using the hammer authentication session, you avoid storing your credentials in the script itself and in the ~/.hammer/cli.modules.d/foreman.yml hammer configuration file.
See the instructions on how to use the sessions:
To enable sessions, add
:use_sessions: trueto the~/.hammer/cli.modules.d/foreman.ymlfile::foreman: :use_sessions: trueNote that if you enable sessions, credentials stored in the configuration file will be ignored.
To start a session, enter the following command:
$ hammer auth loginYou are prompted for your Satellite credentials, and logged in. You will not be prompted for the credentials again until your session expires.
The default length of a session is 60 minutes. You can change the time to suit your preference. For example, to change it to 30 minutes, enter the following command:
$ hammer settings set --name idle_timeout --value 30 Setting [idle_timeout] updated to [30]To see the current status of the session, enter the following command:
$ hammer auth statusTo end the session, enter the following command:
$ hammer auth logout
Chapter 4. Configuring Hammer Copy linkLink copied to clipboard!
The default location for global hammer configuration is:
-
/etc/hammer/cli_config.yml for general
hammersettings - /etc/hammer/cli.modules.d/ for CLI module configuration files
You can set user specific directives for hammer (in ~/.hammer/cli_config.yml) as well as for CLI modules (in respective .yml files under ~/.hammer/cli.modules.d/).
To see the order in which configuration files are loaded, as well as versions of loaded modules, use:
$ hammer -d --version
Loading configuration for many CLI modules can slow down the execution of hammer commands. In such a case, consider disabling CLI modules that are not regularly used.
Apart from saving credentials as described in Chapter 3, Hammer authentication, you can set several other options in the ~/.hammer/ configuration directory. For example, you can change the default log level and set log rotation with the following directives in ~/.hammer/cli_config.yml. These directives affect only the current user and are not applied globally.
:log_level: 'warning'
:log_size: 5 #in MB
Similarly, you can configure user interface settings. For example, set the number of entries displayed per request in the Hammer output by changing the following line:
:per_page: 30
This setting is an equivalent of the --per-page Hammer option.
4.1. Setting a default organization and location context Copy linkLink copied to clipboard!
Many hammer commands are organization specific. You can set a default organization and location for hammer commands so that you do not have to specify them every time with the --organization and --location options.
Specifying a default organization is useful when you mostly manage a single organization, as it makes your commands shorter. However, when you switch to a different organization, you must use hammer with the --organization option to specify it.
Procedure
Set a default organization:
$ hammer defaults add --param-name organization \ --param-value "Your_Organization"You can find the name of your organization with the
hammer organization listcommand.Optional: Set a default location:
$ hammer defaults add --param-name location \ --param-value "Your_Location"You can find the name of your location with the
hammer location listcommand.
Verification
Review the currently specified default settings:
$ hammer defaults list
4.2. Increasing the logging level for Hammer Copy linkLink copied to clipboard!
You can find the log in ~/.hammer/log/hammer.log.
Procedure
In
/etc/hammer/cli_config.yml, set the:log_level:option todebug::log_level: 'debug'
Chapter 5. Using interactive Hammer shell Copy linkLink copied to clipboard!
You can issue hammer commands through an interactive shell. Start the shell:
$ hammer shell
In the shell, you can enter sub-commands directly without typing "hammer", which can be useful for testing commands before using them in a script. To exit the shell, type exit or press Ctrl + D.
Chapter 6. Formatting Hammer output Copy linkLink copied to clipboard!
You can modify the default formatting of the output of hammer commands to simplify the processing of this output by other command line tools and applications. For example, to list organizations in a CSV format with a custom separator (in this case a semicolon), use the following command:
$ hammer --csv --csv-separator ";" organization list
Output in CSV format is useful for example when you need to parse IDs and use them in a for loop.
Several other formatting options are available with the --output option:
$ hammer --output output_format organization list
Replace output_format with one of:
-
table– generates output in the form of a human readable table (default). -
base– generates output in the form of key-value pairs. -
yaml– generates output in the YAML format. -
csv– generates output in the Comma Separated Values format. To define a custom separator, use the--csvand--csv-separatoroptions instead. -
json– generates output in the JavaScript Object Notation format. -
silent– suppresses the output.
Chapter 7. Hiding header output from Hammer commands Copy linkLink copied to clipboard!
When you use any hammer command, you have the option of hiding headers from the output. If you want to pipe or use the output in custom scripts, hiding the output is useful.
-
To hide the header output, add the
--no-headersoption to any hammer command.
Chapter 8. Using JSON for complex parameters Copy linkLink copied to clipboard!
JSON is the preferred way to describe complex parameters.
An example of JSON formatted content appears below:
$ hammer compute-profile values create --compute-profile-id 22 --compute-resource-id 1 --compute-attributes=
'{
"cpus": 2,
"corespersocket": 2,
"memory_mb": 4096,
"firmware": "efi",
"resource_pool": "Resources",
"cluster": "Example_Cluster",
"guest_id": "rhel8",
"path": "/Datacenters/EXAMPLE/vm/",
"hardware_version": "Default",
"memoryHotAddEnabled": 0,
"cpuHotAddEnabled": 0,
"add_cdrom": 0,
"boot_order": [
"disk",
"network"
],
"scsi_controllers":[
{
"type": "ParaVirtualSCSIController",
"key":1000
},
{
"type": "ParaVirtualSCSIController",
"key":1001
}
]
}'
Chapter 9. Troubleshooting Satellite by using Hammer Copy linkLink copied to clipboard!
You can use the hammer ping command to check the status of core Satellite services. Together with the satellite-maintain service status command, this can help you to diagnose and troubleshoot Satellite issues. If all services are running as expected, the output looks as follows:
$ hammer ping
database:
Status: ok
Server Response: Duration: 0ms
cache:
servers:
1) Status: ok
Server Response: Duration: 1ms
candlepin:
Status: ok
Server Response: Duration: 17ms
candlepin_auth:
Status: ok
Server Response: Duration: 14ms
candlepin_events:
Status: ok
message: 4 Processed, 0 Failed
Server Response: Duration: 0ms
katello_events:
Status: ok
message: 5 Processed, 0 Failed
Server Response: Duration: 0ms
pulp3:
Status: ok
Server Response: Duration: 5083ms
pulp3_content:
Status: ok
Server Response: Duration: 5051ms
foreman_tasks:
Status: ok
Server Response: Duration: 2ms
Chapter 10. Hammer cheat sheet Copy linkLink copied to clipboard!
Hammer is a command-line tool provided with Red Hat Satellite 6. You can use Hammer to configure and manage a Satellite Server by using either CLI commands or shell script automation. Run hammer full-help on Satellite to view the complete Hammer CLI help.
10.1. General information Copy linkLink copied to clipboard!
| Subcommand | Description and tasks |
|---|---|
|
| Display hammer commands and options, append after a subcommand to get more information |
| org |
The setting is organization-specific, append
|
| loc |
The setting is location-specific, append
|
Note: This cheat sheet assumes saved credentials in ~/.hammer/cli_config.yml. For more information, see Chapter 3, Hammer authentication.
10.2. Organizations, locations, and repositories Copy linkLink copied to clipboard!
| Subcommand | Description and tasks |
|---|---|
|
| Create an organization:
List organizations:
|
|
| See the options for organization |
|
| Upload a subscription manifest:
|
|
| Enable a repository:
|
|
| Synchronize a repository:
Create a custom repository:
Upload content to a custom repository:
|
10.3. Content life cycles Copy linkLink copied to clipboard!
| Subcommand | Description and tasks |
|---|---|
|
| Create a life cycle environment:
List life cycle environments:
|
|
| Create a content view:
Add repositories to a content view:
Add Puppet modules to a content view:
Publishing a content view:
Promoting a content view:
Incremental update of a content view:
|
10.4. Provisioning environments Copy linkLink copied to clipboard!
| Subcommand | Description and tasks |
|---|---|
|
| Create a domain:
|
|
| Add a subnet:
|
|
| Create a compute resource:
|
|
| Add an installation medium:
|
|
| Add a partition table:
|
|
| Add a provisioning template:
|
|
| Add an operating system:
|
10.5. Activation keys Copy linkLink copied to clipboard!
| Subcommand | Description and tasks |
|---|---|
|
| Create an activation key:
Add a subscription to the activation key:
|
10.6. Users and permissions Copy linkLink copied to clipboard!
| Subcommand | Description and tasks |
|---|---|
|
| Create a user:
Add a role to a user:
|
|
| Create a user group:
Add a role to a user group:
|
|
| Create a role:
|
|
| Create a filter and add it to a role:
|
10.7. Errata Copy linkLink copied to clipboard!
| Subcommand | Description and tasks |
|---|---|
|
| List errata:
Find erratum by CVE:
Inspect erratum:
|
|
| List errata applicable to a host:
Apply errata to a host:
|
10.8. Hosts Copy linkLink copied to clipboard!
| Subcommand | Description and tasks |
|---|---|
|
| Create a host group:
Add an activation key to a host group:
|
|
| Create a host (inheriting parameters from a host group):
Remove the host from host group:
|
|
| Add a job template for remote execution:
|
|
| Start a remote job:
Monitor the remote job:
|
10.9. Tasks Copy linkLink copied to clipboard!
| Subcommand | Description and tasks |
|---|---|
|
| List all tasks:
|
Chapter 11. Hammer reference Copy linkLink copied to clipboard!
You can review the usage of Hammer statements.
This reference is up to date with the versions of Hammer components released for Satellite 6.17.