2000 Working with the Digital Rebar CLI¶
10 Minutes intermediate
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¶
Additional Labs:
Concepts¶
- cli
- machines
- events
- alerts
- catalog
Explore drpcli
¶
Setup CLI Environment¶
This step will provide you a terminal to window / shell to do drpcli
commands.
1. Navigate to the [Machines](ux://machines) view
1. Open the editor for the DRP endpoint machine
1. Click the `Remote` button in the upper right of new panel
The `Remote` button opens an SSH session from within the Portal.
1. Resize the window for comfort
1. 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](https://docs.rackn.io/stable/getting-started/install/install-cloud/#install-via-terraform), then these values will be provided
```sh
export RS_KEY=<username>:<password>
```
For example:
```sh
export RS_KEY='rocketskates:r0cketsk8ts'
```
1. Open the [files](ux://files) view
1. Click `drpcli.<arch>.linux` where arch is amd64, arm64, or ppc64le to download
1. Click the download button
1. Open a terminal in your home directory
1. Put the binary in place and make executable
```sh
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
```
1. 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](https://docs.rackn.io/stable/getting-started/install/install-cloud/#install-via-terraform), then these values will be provided
```sh
export RS_KEY=<username>:<password>
export RS_ENDPOINT=https://<DRP IP>:8092
```
For example:
```sh
export RS_KEY='rocketskates:r0cketsk8ts'
export RS_ENDPOINT=https://10.10.10.1:8092
```
1. Open the [files](ux://files) view
1. Click `drpcli.<arch>.darwin` where arch is amd64 or arm64 to download
1. Click the download button
1. Open a terminal in your home directory
1. Put the binary in place and make executable
```sh
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
```
1. 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](https://docs.rackn.io/stable/getting-started/install/install-cloud/#install-via-terraform), then these values will be provided
```sh
export RS_KEY=<username>:<password>
export RS_ENDPOINT=https://<DRP IP>:8092
```
For example:
```sh
export RS_KEY='rocketskates:r0cketsk8ts'
export RS_ENDPOINT=https://10.10.10.1:8092
```
1. Open the [files](ux://files) view
1. Click `drpcli.amd64.windows` to download
1. Open a powershell terminal
1. Put the binary in place and make executable
```powershell
cd Downloads
cp drpcli.exe c:\Windows
cp drpcli.exe c:\Windows\jq.exe
```
1. 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](https://docs.rackn.io/stable/getting-started/install/install-cloud/#install-via-terraform), then these values will be provided
```powershell
$env:RS_KEY = '<username>:<password>'
$env:RS_ENDPOINT = 'https://<DRP IP>:8092'
```
For example:
```powershell
$env:RS_KEY = 'rocketskates:r0cketsk8ts'
$env:RS_ENDPOINT = 'https://10.10.10.1:8092'
```
Check Versions¶
-
Check
drpcli
versionsh drpcli version
This should display something like: ```sh Version: v4.10.0 ```
-
Check
jq
versionsh jq -v
This should display something like: ```sh gojq 0.12.3 (rev: HEAD/go1.18.2) ```
-
Redo the previous
Setup CLI Environment
step if those commands fail
Test Access¶
-
Make sure that the environment is configured correctly
sh drpcli info get | jq -r .version
This should display something like: ``` v4.10.0 ```
-
Redo the previous
Setup CLI Environment
if this commands fail
Experiment with Alerts¶
-
Create an alert
sh drpcli alerts post INFO lab2000
-
Navigate to Alerts
-
See the newly created alert in the table The table will live update as other things change.
-
List the alerts from the CLI
sh drpcli alerts list Name=lab2000
-
Acknowledge the Alert from the CLI
sh 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¶
-
Create a machine from the CLI
sh drpcli machines create lab2000
-
Look at the machine in the Portal The machine view will update as the CLI makes changes.
-
Show the machine in the CLI
sh drpcli machines show Name:lab2000
This will show the JSON object for that machine.
-
Set a workflow on the machine
sh drpcli machines workflow Name:lab2000 universal-start
This will show the JSON object for that machine.
-
Create a context container for the machine
sh drpcli machines update Name:lab2000 '{ "Context": "drpcli-runner" }'
This will show the JSON object for that machine.
-
Notice the machine run the universal-start workflow
-
Count the machines in the system
sh drpcli machines count
This will show the number machines in the system. Something like: `2`.
-
Use the CLI to wait for changes in the object
sh drpcli machines await Name:lab2000 'Description=Eq(lab2000)'
This command will wait until the machine's description changes. Go to the [machine](ux://machines/Name:lab2000), change the Description, and click in the white space around the description. The command returns `complete`.
-
Remove the machine
sh drpcli machines cleanup Name:lab2000
This returns that the machine is deleted. Notice the [machine](ux://machines) is removed from the Portal.
-
Count the machines in the system (again)
sh 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¶
-
Install the dev-library content pack
sh drpcli catalog item install dev-library --version=tip
A JSON object of the `dev-library` content pack will be returned.
-
Subscribe for events
sh drpcli events watch contents.*.dev-library
This command will run until stopped.
-
Navigate to Catalog
- Select
dev-library
row and clickDelete
-
Watch for the update events. In the shell, the previously running command will show a JSON event indicating that the content pack was deleted.
-
Stop the event watcher in the shell by pressing cntrl-C