Configure password less login for hammer command line tool.

Solution Verified - Updated

Environment

  • Red Hat Satellite 6

Issue

  • Each time hammer command is invoked in Satellite terminal, it asks for username and password:

    sat [~/.hammer] # hammer organization list
    [Foreman] Username: admin
    
    [Foreman] Password for admin: 
    
IDNAMELABELDESCRIPTION
1Default OrganizationDefault_Organization
3ExampleExample


- How to configure the hammer client on Satellite 6 not to prompt for username and password?

- Can hammer client be configured to avoid asking user/password every time it is executed?

- Hammer command line management tool asks for password each time the command is invoked.

- Even after making required changes in `/etc/foreman-maintain/foreman-maintain.yml` file, the hammer command still fails with error `Invalid Username and Password`.


## Resolution

- In order to skip username and password check **for Satellite 6.2 and earlier**, create the directory `~/.hammer` and then create a `cli_config.yml` file in the directory, adding the following content to the file:
Put the following values inside the file:

   <pre>
   :foreman:
    :host: 'https://satellite.example.com'
    :username: 'admin'
    :password: 'password'
  </pre>

- **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.
You can also add your credentials manually to the `~/.hammer/cli.modules.d/foreman.yml` configuration file:

   <pre>
   :foreman:
    :username: 'admin'
    :password: 'password'
  </pre>

**Important Notes:**

- When creating a YAML file (e.g. `cli_config.yml`) follow these rules:

  - Tabs are not allowed (use spaces only).

  - The properties MUST be indented (host, username, password) with 1 or more spaces. If indenting `:host:` by one space, then all the other properties must be indented by one space as well.

  - If these rules are not followed, the following error message will be displayed:


    ```
    sat [~/.hammer] # 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-0.1.4.11/lib/hammer_cli/settings.rb:38:in `load_from_file'
        from /usr/share/gems/gems/hammer_cli-0.1.4.11/lib/hammer_cli/settings.rb:22:in `block in load_from_paths'
        from /usr/share/gems/gems/hammer_cli-0.1.4.11/lib/hammer_cli/settings.rb:16:in `each'
        from /usr/share/gems/gems/hammer_cli-0.1.4.11/lib/hammer_cli/settings.rb:16:in `load_from_paths'
        from /usr/share/gems/gems/hammer_cli-0.1.4.11/bin/hammer:40:in `<top (required)>'
        from /usr/bin/hammer:23:in `load'
        from /usr/bin/hammer:23:in `<main>'
    ```


- Please note that:
- The credentials stored in `~/.hammer/cli.modules.d/foreman.yml` must match the credentials stored in `/etc/foreman-maintain/foreman-maintain.yml`.

- In addition, the credentials stored in `/etc/foreman-maintain/foreman-maintain.yml` should **not** be surrounded by single quotes, unlike the `~/.hammer/cli.modules.d/foreman.yml` file.  Here is an example `foreman-maintain.yml` file:

       <pre>
       ---
       :foreman:
         :username: admin
         :password: mypassword
       </pre>

For more KB articles/solutions related to Red Hat Satellite 6.x hammer Issues, please refer to the [Consolidated Troubleshooting Article for Red Hat Satellite 6.x hammer-related Issues](https://access.redhat.com/articles/6450521)




SBR
Product(s)
Category
Tags

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.