23.1.10. 2000 Working with the Digital Rebar CLI

23.1.10.1. Overview

  • Id: 2000

  • Time: 10 Minutes

  • Enabled: Yes

  • Difficulty: intermediate

  • Tags: fundamentals

  • Concepts: cli, machines, events, alerts, catalog

Video Link

23.1.10.2. Objective

Learn how to use Digital Rebar by the command line for programmatic control

Using the Digital Rebar CLI, this lab will explore the ability to get and control DRP programmatically.

Business ROI: Improved automation skills results in improved IaC contruction and integration.

23.1.10.3. Prerequisites

Required Labs:

  • 1200

23.1.10.3.1. Explore drpcli

23.1.10.3.1.1. Setup CLI Environment

This step will provide you a terminal to window / shell to do drpcli commands.

  1. Navigate to the Machines view

  2. Open the editor for the DRP endpoint machine

  3. Click the Remote button in the upper right of new panel

    The Remote button opens an SSH session from within the Portal.

  4. Resize the window for comfort

  5. Set the endpoint and access credentials

    During Lab 1000, Install Digital Rebar, you may have changed the access username and password. You will need to use those now to set an environment variable for accessing DRP. Since you are on the DRP Endpoint, the endpoint default value is sufficient.

    If you used the Terraform Setup, then these values will be provided

    export RS_KEY=<username>:<password>
    

    For example:

    export RS_KEY='rocketskates:r0cketsk8ts'
    

23.1.10.3.1.2. Check Versions

  1. Check drpcli version

    drpcli version
    

    This should display something like:

    Version: v4.10.0
    
  2. Check jq version

    jq -v
    

    This should display something like:

    gojq 0.12.3 (rev: HEAD/go1.18.2)
    
  3. Redo the previous Setup CLI Environment step if those commands fail

23.1.10.3.1.3. Test Access

  1. Make sure that the environment is configured correctly

    drpcli info get | jq -r .version
    

    This should display something like:

    v4.10.0
    
  2. Redo the previous Setup CLI Environment if this commands fail

23.1.10.3.1.4. Experiment with Alerts

  1. Create an alert

    drpcli alerts post INFO lab2000
    
  2. Navigate to Alerts

  3. See the newly created alert in the table

    The table will live update as other things change.

  4. List the alerts from the CLI

    drpcli alerts list Name=lab2000
    
  5. Acknowledge the Alert from the CLI

    drpcli alerts ack `drpcli alerts list Name=lab2000 | jq -rc 'head|.Uuid'`
    

    Note the two drpcli calls. The inner drpcli call is used to get the Uuid of the most recent alert. The outer drpcli call is used to acknowledge it.

23.1.10.3.1.5. Playing with Machines with the CLI

  1. Create a machine from the CLI

    drpcli machines create lab2000
    
  2. Look at the machine in the Portal

    The machine view will update as the CLI makes changes.

  3. Show the machine in the CLI

    drpcli machines show Name:lab2000
    

    This will show the JSON object for that machine.

  4. Set a workflow on the machine

    drpcli machines workflow Name:lab2000 universal-start
    

    This will show the JSON object for that machine.

  5. Create a context container for the machine

    drpcli machines update Name:lab2000 '{ "Context": "drpcli-runner" }'
    

    This will show the JSON object for that machine.

  6. Notice the machine run the universal-start workflow

  7. Count the machines in the system

    drpcli machines count
    

    This will show the number machines in the system. Something like: 2.

  8. Use the CLI to wait for changes in the object

    drpcli machines await Name:lab2000 'Description=Eq(lab2000)'
    

    This command will wait until the machine’s description changes.

    Go to the machine, change the Description, and click in the white space around the description.

    The command returns complete.

  9. Remove the machine

    drpcli machines cleanup Name:lab2000
    

    This returns that the machine is deleted. Notice the machine is removed from the Portal.

  10. Count the machines in the system (again)

    drpcli machines count
    

    This will show the number machines in the system. Something like: 2 The value is one less than before.

23.1.10.3.1.6. Watch for Events from the CLI

  1. Install the dev-library content pack

    drpcli catalog item install dev-library --version=tip
    

    A JSON object of the dev-library content pack will be returned.

  2. Subscribe for events

    drpcli events watch contents.*.dev-library
    

    This command will run until stopped.

  3. Navigate to Catalog

  4. Select dev-library row and click Delete

  5. Watch for the update events.

    In the shell, the previously running command will show a JSON event indicating that the content pack was deleted.

  6. Stop the event watcher in the shell by pressing cntrl-C