Using Hammer CLI
You can perform almost all actions using the Hammer CLI that you can perform through the orcharhino management UI. 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.
You can view a list of command using hammer --help
.
Each command and subcommand contains further help, for example hammer os -h
or hammer os create -h
.
This guide uses orcharhino specific terminology. If you are new to orcharhino or unsure about certain terms, have a look at our glossary. |
Installing Hammer CLI
The Hammer CLI is 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:
# dnf install rubygem-hammer_cli_katello
You can install additional Hammer CLI plugins.
Plugin | Package |
---|---|
Ansible |
|
Boot Disk |
|
Discovery |
|
OpenSCAP |
|
Remote Execution |
|
SCC Manager |
|
Salt |
|
During the installation of orcharhino, a default configuration is stored in /etc/hammer/
and /etc/hammer/cli.modules.d/
.
Hammer CLI searches for a configuration in /etc/hammer/
and ~/.hammer/
.
Both directories contain the generic and plugin-specific configuration.
You can set the path to the configuration file using -c /path/to/config/file.yml
while using the Hammer CLI.
Configuring Authentication
You need to configure authentication for Hammer to run commands on your orcharhino.
You can use the admin
user or any other orcharhino user with the appropriate permissions.
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 ~/.hammer/cli.modules.d/foreman.yml
.
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.example.com'
Viewing Hammer CLI Output
Be default, Hammer displays the generated output in tabular form.
This can be controlled with the parameter --output format
.
Formats supported by orcharhino are base
, table
, silent
, csv
, yaml
, and json
.
A shorter form of the output format of CSV data can be controlled using the Hammer option --csv
.
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 My_Output_File
option.
Create the list of hosts configured in orcharhino in CSV format without headings in the file host_list.csv
.
# hammer --csv --no-headers --output-file host_list.csv host list
Hammer CLI Examples
-
You can create an operating system with the following command:
# hammer os create --name "SLES15" --family "Suse" --major "15" --description "SLES 15"
-
Create a global parameters in a loop:
for var in 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
-
Deploy multiple hosts using a
.csv
file andmulti_host_deploy.sh
bash script:-
Create a bash script:
#!/bin/bash while IFS=, read -r host_name host_group organization location do hammer host create \ --name "${host_name}" \ --hostgroup "${host_group}" \ --organization "${organization}" \ --location "${location}" hammer host start --name "${host_name}.example.com" done < hosts.csv
-
Define an arbitrary number of hosts by setting the
host_name
,host_group
,organization
, andlocation
parameters in thehosts.csv
file:# cat hosts.csv host1,CentOS 7,My_Organization,My_Location_A host2,SLES 15,My_Organization,My_Location_B
-
Deploy multiple hosts at once by running the
multi_host_deploy.sh
shell script as follows:# ./multi_host_deploy.sh
-