Run Scripts on Delegates using Delegate Configurations
A Delegate Configuration enables you to run a startup script on the host/container/pod for a Harness Delegate during installation. You can create a single Delegate Configuration and apply it to multiple Delegates.
In this topic:
- Before You Begin
- Review: Delegate Configuration Summary
- Step 1: Create a Delegate Configuration script
- Option: Secrets in Scripts
- Step 2: Applying a Script
- See Also
Before You Begin
Review: Delegate Configuration Summary
A Delegate Configuration lets you install and run script and software during Delegate installation.
To do this, you create a Delegate Configuration containing the commands for installing and running the software.
Each time you add a Delegate, you can apply the Configuration.
When the Delegate is started, the commands to install and run the software are executed.
For example, a Delegate Configuration that installs Terraform:
curl -O -L https://releases.hashicorp.com/terraform/0.11.13/terraform_0.11.13_linux_amd64.zip
sudo mv terraform /usr/local/bin/
For examples of Delegate Profile scripts, see Common Delegate Configuration Scripts.
Your Harness account comes with a default Primary Configuration.
When you install a new Delegate you can select the Primary Configuration. It cannot be renamed or deleted.
You can add any script to the Primary Configuration, and apply it to any Delegate.
What Can I Run In a Configuration?
You can add any commands supported on the host/container/pod running the Delegate. Linux shell commands are most common. If kubectl, Helm, or Docker is running on the host/container/pod where you install the Delegate, then you can use their commands.
The base image for the Delegate is Ubuntu 18.04 or later, and so any default Ubuntu packages may be used in the Delegate Configuration script.
All Delegates include cURL and unzip as part of their installation package, and so you may use cURL and unzip in your Delegate Configuration scripts without installing them. The following script will work without having to install any packages:
usr/bin/apt-get install -y python
curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
./awscli-bundle/install -b ~/bin/aws
When is the Script Executed?
Delegate Configuration scripts are applied under the following conditions:
- New Delegate: when you add a Delegate Configuration as you set up the Delegate, the script commands are executed after the Delegate is started.
The Configuration script execution timeout limit is 10 minutes.
Step 1: Create a Delegate Configuration script
To create a Delegate Configuration script, in Harness, at the Project/Org/Account level, click Setup.
Click Delegates, and then click the Delegate Configurations tab.
Click New Delegate Configuration.
Name the Delegate Configuration and click Save and Continue.
In Initialization Scripts, enter the script you want to run.
When you are done, click Save and Continue.
In Scope, define a scope for the Delegate Configuration, if needed. See Scope Harness Delegates to Environments.
Option: Secrets in Scripts
You can use Harness encrypted text and file secrets in your script. This is very common for usernames and passwords.
To reference a secret, use the
See Add Text Secrets.
Step 2: Applying a Script
You can apply the script when you add the Delegate Configuration to the Delegate.
When you add a new Delegate you select its first Delegate Configuration. The script in that Delegate Configuration will run once the Delegate is running and registered with Harness.
- It might take a few minutes to apply the script in the Delegate Configuration.