How to configure passwordless login for the "hammer" command line tool

The hammer command line management tool for Red Hat Satellite is used to provision hosts, edit resouce or group attributes and can intereact and manipulate hosts, capsules and domains.

By default, each time the hammer command is invoked it asks for a password. For example:

[admin@satellite:~]% hammer organization list
[Foreman] Username: admin
[Foreman] Password for admin: 
ID | NAME                 | LABEL                | DESCRIPTION
1  | Default Organization | Default_Organization |            
2  | TestOrg              | Test_Org             | Test Organisation

Satellite 6.2 and earlier

In order to skip username and password checks in Satellite 6.2 and earlier, create the file ~/.hammer/cli_config.yml and add the following entries to the file:

  :host: 'https://satellite.myfqdn'
  :username: 'admin'
  :password: 'password'

NOTE: The credentials stored in ~/.hammer/cli_config.yml must match the credentials stored in /etc/foreman-maintain/foreman-maintain-hammer.yml.

Satellite 6.3 and later

For Satellite 6.3 and later, if you ran the Satellite installation with the --foreman-admin-username and --foreman-admin-password options, the credentials you entered are stored in the ~/.hammer/cli.modules.d/foreman.yml configuration file, and hammer does not prompt for your credentials.

NOTE: You can add your credentials manually to the ~/.hammer/cli.modules.d/foreman.yml configuration file. For example:

  :username: 'admin'
  :password: 'password'


YAML Syntax

When creating a yaml file, the follow rules apply:

  1. Tabs are not allowed (use spaces only).
  2. The properties MUST be indented (host, username, password) with 1 or more spaces. For example, If indenting ":host:" by two spaces, then all the other properties must be indented by two spaces as well.

If the above rules are not followed then the following error will occur:

[admin@satellite:~]% hammer organization list
/usr/share/ruby/psych.rb:205:in 'parse': (<unknown> did not find expected key while parsing a block mapping at line 3 column 2 (Psych::SyntaxError)
    from /usr/share/ruby/psych.rb:205:in 'parse_stream'
    from /usr/share/ruby/psych.rb:153:in 'parse'
    from /usr/share/ruby/psych.rb:129:in 'load'
    from /usr/share/gems/gems/hammer_cli- 'load_from_file'
    from /usr/share/gems/gems/hammer_cli- 'block in load_from_paths'
    from /usr/share/gems/gems/hammer_cli- 'each'
    from /usr/share/gems/gems/hammer_cli- 'load_from_paths'
    from /usr/share/gems/gems/hammer_cli- '<top (required)>'
    from /usr/bin/hammer:23:in 'load'
    from /usr/bin/hammer:23:in '<main>'