Hammer CLI Guide¶
Almost all actions that can be performed via the Management UI can also be initiated via the Hammer Command Line Interface (CLI).
During the installation of orcharhino the Hammer CLI is installed and configured. Like orcharhino itself, the functionality of Hammer CLI can be extended by plugins.
The Hammer CLI is usually installed automatically during the installation of orcharhino. If this is not the case, or if you want to install the Hammer CLI on a separate host, you can do this with the following command:
yum install tfm-rubygem-hammer_cli_katello
As already mentioned, additional Hammer CLI plugins can be installed.
yum search hammer_cli to search for additional plugins.
Below is a list of other interesting Hammer CLI plugins:
During the installation of orcharhino, a default configuration is stored in
Hammer CLI searches for a configuration in the following directories:
~/.hammer/) contains the generic configuration and
~/.hammer/cli.modules.d/) contains a plugin-specific configuration.
The path to the configuration file can also be set by
-c CONFIG_FILE while using the Hammer CLI.
For the use of Hammer CLI commands an authentication to orcharhino is necessary. This can be done by the “admin” user or by any other orcharhino user. Note, however, that appropriate permissions are required to execute certain commands.
Authentication can either be done individually for each command or can also be specified in the configuration.
During the orcharhino installation the authentication for the system root user is stored in
If the authentication is necessary for another system user or is configured on a different host using Hammer CLI, create
~/.hammer/cli_config.yml with the following contents:
:foreman: # Credentials. You'll be asked for the interactively if you leave them blank here :username: 'admin' :password: 'admin' # Check API documentation cache status on each request :refresh_cache: false # API request timeout in seconds, set -1 for infinity :request_timeout: 120 # Specify the orcharhino host. If unset (or commented out), localhost is used. #:host: 'https://orcharhino.host
With Hammer you can control orcharhino almost completely via the CLI. Many different commands are available for this purpose. As already mentioned, the functionality can be extended by hammer plugins. Documenting all commands at this point would go far beyond the scope of this documentation.
Therefore this documentation describes the general use of Hammer.
A list of all available commands can be retrieved via
For each command and subcommand the list of options and available subcommands can be shown with
hammer os -h and
hammer os create -h.
Hammer offers an interactive shell that can be used to execute multiple commands one after the other. This can be useful for testing purposes, before packing the commands into a shell script, which controls the Hammer commands. To exit the Hammer Shell you have to enter “exit” or “CTRL+D”.
Normally Hammer displays the generated output in tabular form.
This can be controlled with the parameter
Supported formats are:
A shorter form of the output format of CSV data (comma separated values) can be controlled via the hammer option
With the option
--no-headers you can suppress the output of the headings.
If you want to write the output directly to a file, you can use the
--output-file <output file> option.
Create the list of hosts configured in orcharhino in CSV format without headings in the file
hammer --csv --no-headers --output-file host_list.csv host list
Target of the first example is to add a Operating System “SLES15”.
First of all, we use
hammer os create -h to show which options are necessary to create the OS.
Afterwards, we use the following construct to create the OS:
[root@or ~]# hammer os create --name "SLES15" --family "Suse" --major "15" --description "SLES 15" Operating system created.
Create some global parameters in a loop:
[root@or ~]# for var in sles10:false sles11:true sles12:true sles15:false; do \ name=$(echo $var | cut -f1 -d:); \ value=$(echo $var | cut -f2 -d:); \ hammer global-parameter set --name $name --value $value; \ done Created parameter [sles10] with value [false]. Created parameter [sles11] with value [true]. Created parameter [sles12] with value [true]. Created parameter [sles15] with value [false].