Bookmark this page

Guided Exercise: Administer Red Hat Satellite with Hammer

Use the Hammer CLI for common tasks and object queries.

Outcomes

  • Check hammer authentication status.

  • Create organizations, users, user groups, and host collections by using Hammer.

As the student user on the workstation machine, use the lab command to prepare your system for this exercise.

This command prepares your environment and ensures that all required resources are available.

[student@workstation ~]$ lab start deploy-hammer

Instructions

  1. On the satellite system, save the status of the Satellite Server to the /root/satellite-YYYYMMDDHM.log file, where YYYYMMDDHM is the year, month, day, hour, and minute when you run the command. Create the objects in the following table by using the hammer command. This exercise provides practice for using the hammer command syntax. The objects that you create are discussed in later sections.

    Object typeName
    OrganizationSecOps
    Host Collection
    • Firewalls

    • IDS

    • LogServers

    1. On workstation, log in to the satellite system as the student user and switch to the root user.

      [student@workstation ~]$ ssh student@satellite
      [student@satellite ~]$ sudo -i
      [sudo] password for student: student
      [root@satellite ~]#
    2. Verify that the /root/.hammer/cli.modules.d/foreman.yml configuration file includes the admin credentials.

      [root@satellite ~]# cat ~/.hammer/cli.modules.d/foreman.yml
      :foreman:
        # Credentials. You'll be asked for them interactively if you leave them blank here
        :username: 'admin'
        :password: 'redhat'
    3. Verify the authentication status for hammer.

      [root@satellite ~]# hammer auth status
      Using configured credentials for user 'admin'.
    4. Save the status of the Satellite Server to the /root/satellite-YYYYMMDDHM.log file. The date in your file name is expected to be different.

      [root@satellite ~]# hammer --output-file satellite-$(date +%Y%m%d%H%M).log ping
      [root@satellite ~]# cat satellite-202259291459.log
      database:
          Status:          ok
          Server Response: Duration: 0ms
      candlepin:
          Status:          ok
          Server Response: Duration: 20ms
      ...output omitted...
    5. Create the SecOps organization. Using organizations is discussed in an upcoming section.

      [root@satellite ~]# hammer organization create \
      --name SecOps \
      --description 'Security Operations Organization'
      Organization created.
    6. Create the Firewalls, IDS, and LogServers host collections. Using host collections is discussed in an upcoming section.

      [root@satellite ~]# hammer host-collection create \
      --name Firewalls \
      --organization SecOps
      Host collection created.
      [root@satellite ~]# hammer host-collection create \
      --name IDS \
      --organization SecOps
      Host collection created.
      [root@satellite ~]# hammer host-collection create \
      --name LogServers \
      --organization SecOps
      Host collection created.
  2. Review the available Capsule Servers. Review the subscription information for the SecOps organization and compare it to the Operations organization.

    1. List the available Capsule Servers. By using the THIN parameter, you request that the command prints only the requisite columns.

      [root@satellite ~]# hammer capsule list --fields THIN
      ---|--------------------------
      ID | NAME
      ---|--------------------------
      1  | satellite.lab.example.com
      ---|--------------------------
    2. Review the capsule information, such as the existing organizations, URL, and active features. Use the capsule ID from the previous step.

      [root@satellite ~]# hammer capsule info --id 1
      Id:            1
      Name:          satellite.lab.example.com
      URL:           https://satellite.lab.example.com:9090
      Host_count:    0
      Features:
       1) Name: Dynflow
       2) Name: Discovery
       3) Name: SSH
       4) Name: Ansible
       5) Name: Openscap
       6) Name: Pulpcore
       7) Name: Logs
      Locations:
          Default Location
      Organizations:
          Default Organization
          Finance
          Operations
          SecOps
      Created at:    2022/07/14 17:01:34
      Updated at:    2022/07/14 17:01:35
    3. List the existing organizations by using the THIN fields parameter.

      [root@satellite ~]# hammer organization list --fields THIN
      ---|----------------------|----------------------|---------------------
      ID | TITLE                | NAME                 | LABEL
      ---|----------------------|----------------------|---------------------
      1  | Default Organization | Default Organization | Default_Organization
      7  | Finance              | Finance              | Finance
      6  | Operations           | Operations           | Operations
      8  | SecOps               | SecOps               | SecOps
      ---|----------------------|----------------------|---------------------
    4. Review the available subscriptions in the Operations organization. Use the Operations organization ID from your previous query. Limit the output to the ID and NAME columns, and format the output as JSON. On the command line, enter field names and output parameters as lowercase.

      [root@satellite ~]# hammer --output json subscription list \
      --organization-id 6 --fields id,name
      [
        {
          "Id": 6,
          "Name": "Red Hat Enterprise Linux Server, Standard (Physical or Virtual Nodes)"
        },
        {
          "Id": 5,
          "Name": "Red Hat Satellite Infrastructure Subscription"
        }
      ]
    5. Review the available subscriptions in the SecOps organization. Use the SecOps organization ID from your previous query. Limit the output to the ID and NAME columns. The list is empty, because no subscriptions were loaded to the SecOps organization.

      [root@satellite ~]# hammer subscription list --organization-id 8 --fields id,name
      ---|-----
      ID | NAME
      ---|-----
  3. Log in to the Satellite web UI by using the admin account and the redhat password. Verify the presence of the objects that you created with the hammer command.

    1. Use your browser to navigate to https://satellite.lab.example.com. Log in by using the admin account and the redhat password.

    2. In the upper-left corner of the web page, set the organization to SecOps. Set the location to Any Location, because your next task is not location-specific.

    3. Navigate to HostsHost Collections. Verify the presence of the collections that were created with Hammer.

  4. From the command line, delete the SecOps organization and the organization's host collections.

    1. Delete the SecOps organization. Deleting the organization also deletes the organization's resources, including host collections.

      Note

      An organization with registered clients cannot be deleted until those clients are moved to another organization.

      [root@satellite ~]# hammer organization delete --name SecOps
      [....................................................................] [100%]
    2. Verify that the SecOps organization is deleted.

      [root@satellite ~]# hammer organization list --fields THIN
      ---|----------------------|----------------------|---------------------
      ID | TITLE                | NAME                 | LABEL
      ---|----------------------|----------------------|---------------------
      1  | Default Organization | Default Organization | Default_Organization
      7  | Finance              | Finance              | Finance
      6  | Operations           | Operations           | Operations
      ---|----------------------|----------------------|---------------------
    3. Verify that the SecOps organization's host collections are also deleted.

      [root@satellite ~]# hammer host-collection list
      ---|------|-------|------------
      ID | NAME | LIMIT | DESCRIPTION
      ---|------|-------|------------
    4. Return to the workstation system as the student user.

      [root@satellite ~]# exit
      logout
      [student@satellite ~]$ exit
      logout
      [student@workstation ~]$
  5. In the Satellite web UI, verify that the deleted objects do not exist.

    1. In the upper-left corner of the web page, set the organization to Default Organization. Set the location to Any Location.

    2. Navigate to AdministerOrganizations. Verify that the SecOps organization does not exist.

    3. Navigate to HostsHost Collections. Verify that no host collections exist.

    4. Log out of the Satellite web UI. In the upper-right corner of the web page, select Admin UserLog Out

Finish

On the workstation machine, change to the student user home directory and use the lab command to complete this exercise. This step is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish deploy-hammer

Revision: rh403-6.11-3ad886e