Run Scripts on Delegates using Delegate Configurations

Updated 1 month ago by Michael Cretzman

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.

A Delegate Configuration is mandatory. The Primary Configuration is the default and contains no script.

In this topic:

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
unzip terraform_0.11.13_linux_amd64.zip
sudo mv terraform /usr/local/bin/
terraform --version

For examples of Delegate Profile scripts, see Common Delegate Configuration Scripts.

Primary Configuration

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"
unzip 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.

Timeouts

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.

Click Finish.

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 <+secrets.getValue("your_secret")> format.

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.

Notes

  • It might take a few minutes to apply the script in the Delegate Configuration.

See Also


Please Provide Feedback