Skip to content

Passing Environment Variables to Workstation at Launch

This example demonstrates how to pass environment variables to a workstation at launch.

Requirements

  • A running Orion instance
  • Orion API Key
  • kuiper role assigned to the user running the script

Script

Warning

If you get a requests.exceptions.SSLError you can pass in the verify=False parameter to the request to disable SSL verification.

Custom environment variables passed at launch

import os
import requests

server = os.environ['SERVER']
token = os.environ['TOKEN']
custom_var = os.environ['CUSTOM_VAR']
idx = int(os.environ['IDX'])


# Identify the user via token
rsp = requests.get(
    f'{server}/titan/identity',
    headers={'Authorization': token}
)
user = rsp.json()['name']

# Create a new workstation
rsp = requests.post(
    f'{server}/kuiper/request',
    headers={'Authorization': token},
    json={
        'instance_type': idx, 
        'user': user,
        'env': {
            'CUSTOM_VAR': custom_var
        }
    }
)

export TOKEN="your-token"export SERVER="https://orion-install"export IDX="999111555"export CUSTOM_VAR="Hello, World!"python custom_var.py

This script will create a workstation with a custom environment variable CUSTOM_VAR set to Hello, World!.

Verification

We can verify this by running env inside of a workstation terminal.

env | grep CUSTOM_VARCUSTOM_VAR=Hello, World!