Scripts
CloudRay scripts empower you to automate tasks on your remote servers using flexible Liquid templates. These templates can include variables, allowing you to customise script execution and reuse scripts across different scenarios.
Creating and Managing Scripts
-
Navigate to “Scripts”: Click on the “Scripts” tab in the main navigation.
-
Click “Add Script”: Start creating a new script template.
-
Enter Details:
- Script Name: Provide a descriptive name for your script (e.g., “Deploy Website”, “Backup Database”).
- Template: Write your script using a combination of Bash commands, Python code, or any language executable via SSH, and Liquid template variables.
-
Save Script: Click “Save Script” to store your script template.
Using Liquid Templates for Dynamic Scripts
CloudRay’s script templates use the Liquid templating language, allowing you to insert variables and logic into your scripts. This makes your scripts more adaptable and reusable.
Built-in CloudRay Variables:
{{ cr.server_name }}
: The name of the server where the script is running.{{ cr.server_ssh_host }}
: The hostname or IP address of the server.{{ cr.script_name }}
: The name of the currently executing script.{{ cr.webhook_query_params }}
: If triggered by a Webhook Receiver, this contains URL query parameters.{{ cr.webhook_post_body }}
: If triggered by a Webhook Receiver, this contains the request body.
Built-in CloudRay Filters:
cr_bash_escape
: Escapes a string so it can be safely used in a Bash script.- Example:
{{ user_input | cr_bash_escape }}
ensures that user input doesn’t break your script.
- Example:
Custom Variables (Variable Groups):
You can create Variable Groups within CloudRay to define key-value pairs. These variables can be referenced in your script templates when you create a Runlog.
Example Script (Bash) with Liquid Template:
#!/bin/bash
SERVER_NAME={{ cr.server_name }}
echo "Running script on $SERVER_NAME"
# Accessing custom variable from Variable Group
API_KEY={{ my_api_key }}
curl "[https://api.example.com/data?key=$API_KEY](https://api.example.com/data?key=$API_KEY)"