Skip to content

::: {.index} pair: Working with the Digital Rebar CLI; Labs :::

2000 Working with the Digital Rebar CLI

Overview

  • Id: 2000
  • Time: 10 Minutes
  • Enabled: Yes
  • Difficulty: intermediate
  • Tags: fundamentals

* Concepts: cli, machines, events, alerts, catalog .. youtube:: rpM0b8nqdVc :privacy_mode: Video Link

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.

Prerequisites

Required Labs:

  • 1200

Explore drpcli

Setup CLI Environment

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

::: {.tabs} ::: {.tab} DRP Shell

  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'
    
    :::

::: {.tab} Linux

  1. Open the files view
  2. Click drpcli.<arch>.linux where arch is amd64, arm64, or ppc64le to download
  3. Click the download button
  4. Open a terminal in your home directory
  5. Put the binary in place and make executable

    cd ~/Downloads
    cp drpcli /usr/local/bin
    cp drpcli /usr/local/bin/jq
    chmod +x /usr/local/bin/drpcli
    chmod +x /usr/local/bin/jq
    
  6. Set the endpoint and access credentials

    During the lab1000, you may have changed the access username and password. You will need to use those now to set an environment variable for accessing DRP.

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

    export RS_KEY=<username>:<password>
    export RS_ENDPOINT=https://<DRP IP>:8092
    

    For example:

    export RS_KEY='rocketskates:r0cketsk8ts'
    export RS_ENDPOINT=https://10.10.10.1:8092
    
    :::

::: {.tab} Darwin

  1. Open the files view
  2. Click drpcli.<arch>.darwin where arch is amd64 or arm64 to download
  3. Click the download button
  4. Open a terminal in your home directory
  5. Put the binary in place and make executable

    cd ~/Downloads
    cp drpcli /usr/local/bin
    cp drpcli /usr/local/bin/jq
    chmod +x /usr/local/bin/drpcli
    chmod +x /usr/local/bin/jq
    
  6. Set the endpoint and access credentials

    During the lab1000, you may have changed the access username and password. You will need to use those now to set an environment variable for accessing DRP.

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

    export RS_KEY=<username>:<password>
    export RS_ENDPOINT=https://<DRP IP>:8092
    

    For example:

    export RS_KEY='rocketskates:r0cketsk8ts'
    export RS_ENDPOINT=https://10.10.10.1:8092
    
    :::

::: {.tab} Windows

  1. Open the files view
  2. Click drpcli.amd64.windows to download
  3. Open a powershell terminal
  4. Put the binary in place and make executable

    cd Downloads
    cp drpcli.exe c:\Windows
    cp drpcli.exe c:\Windows\jq.exe
    
  5. Set the endpoint and access credentials

    During the lab1000, you may have changed the access username and password. You will need to use those now to set an environment variable for accessing DRP.

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

    $env:RS_KEY = '<username>:<password>'
    $env:RS_ENDPOINT = 'https://<DRP IP>:8092'
    

    For example:

    $env:RS_KEY = 'rocketskates:r0cketsk8ts'
    $env:RS_ENDPOINT = 'https://10.10.10.1:8092'
    
    ::: :::

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

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

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.

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.

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