Common Delegate Scripts
A Delegate INIT
environment variable enables you to run a startup script on the host/container/pod for a Harness Delegate when the Delegate is installed or restarted.
For information on Delegate INIT, see Run Initialization Scripts on Delegates.
This topic provides information on script availability and some common Delegate INIT scripts.
Terraform
# Install TF
curl -O -L https://releases.hashicorp.com/terraform/0.12.25/terraform_0.12.25_linux_amd64.zip
unzip terraform_0.12.25_linux_amd64.zip
yes | mv ./terraform /usr/bin/
# Check TF install
terraform --version
Upgrade to Terraform_0.13.3
##terraform update
set +x
apt-get update
apt-get install wget
apt-get -y install git
wget https://releases.hashicorp.com/terraform/0.13.3/terraform_0.13.3_linux_amd64.zip apt-get install unzip
unzip terraform_0.13.3_linux_amd64.zip
cp terraform /usr/bin/
terraform --version
Install Terraform_0.13.3 and Terragrunt
#Terraform
curl -O -L https://releases.hashicorp.com/terraform/0.13.3/terraform_0.13.3_linux_amd64.zip
unzip terraform_0.13.3_linux_amd64.zip
yes | mv ./terraform /usr/bin/
# Check TF install
terraform --version
#Terragrunt
wget https://github.com/gruntwork-io/terragrunt/releases/download/v0.28.0/terragrunt_linux_amd64
yes | mv terragrunt_linux_amd64 terragrunt
chmod u+x terragrunt
yes | mv terragrunt /usr/local/bin/terragrunt
terragrunt --version
Helm 2
Installing Helm and Tiller in the Delegate's cluster:
helm init --client-only
option, as Tiller is not needed. See Helm charts for more information.# Add the Helm version that you want to install
HELM_VERSION=v2.14.0
# v2.13.0
# v2.12.0
# v2.11.0
export DESIRED_VERSION=${HELM_VERSION}
echo "Installing Helm $DESIRED_VERSION ..."
curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get | bash
# If Tiller is already installed in the cluster
helm init --client-only
# If Tiller is not installed in the cluster
# helm init
DESIRED_VERSION
is used by a function in the Helm install script.If Helm is being installed in a cluster outside of the Delegate's cluster ensure that the kubeconfig in the Delegate cluster is pointing to the correct cluster using:
kubectl config current-context cluster_name
--tls
parameter with your commands. For more information, see Command Flags in Helm Deploy step in the Helm Deployment guide, and see Using SSL Between Helm and Tiller from Helm, and the section Securing your Helm Installation in that document.Here is an example of how to add a Helm chart from a private repo using secrets repoUsername
and repoPassword
from Harness Secrets Management.
# Other installation method
# curl https://raw.githubusercontent.com/helm/helm/master/scripts/get > get_helm.sh
# chmod 700 get_helm.sh
# ./get_helm.sh
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get | bash
helm init --client-only
helm repo add --username ${secrets.getValue("repoUsername")} --password ${secrets.getValue("repoPassword")} nginx https://charts.bitnami.com/bitnami
helm repo update
Helm 3
You do not need to add a Delegate INIT for Helm 3. Harness includes Helm 3 support in any Delegate that can connect to the target Kubernetes cluster.
For more information, see Upgrade to Helm 3 Charts in Kubernetes Services and Upgrade Native Helm 2 Deployments to Helm 3.
Pip
apt-get update
before running any apt-get
commands.apt-get update
# Install pip
apt-get -y install python-pip
# Check pip install
pip -v
Unzip
apt-get update
before running any apt-get
commands.apt-get update
# Install Unzip
apt-get install unzip
AWS CLI
The following script installs the AWS CLI version 2 on the Delegate host.
# Install AWS CLI
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
./awscli-bundle/install -b ~/bin/aws
# install
sudo ./aws/install
# Check AWS CLI install
aws --version
AWS Describe Instance
The following script describes the EC2 instance based on its private DNS hostname, which is also the name in the Delegate's Hostname field:
aws ec2 describe-instances --filters "Name=network-interface.private-dns-name,Values=ip-10-0-0-205.ec2.internal" --region "us-east-1"
The value for the Values
parameter is simply the Hostname of the Delegate.
AWS List All Instances in a Region
The following script will list all of the EC2 instances in the region you supply:
aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId,State.Name,InstanceType,PrivateIpAddress,PublicIpAddress,Tags[?Key==`Name`].Value[]]' --region "us-east-1" --output json | tr -d '\n[] "' | perl -pe 's/i-/\ni-/g' | tr ',' '\t' | sed -e 's/null/None/g' | grep '^i-' | column -t
Git CLI
apt-get update
before running any apt-get
commands.apt-get update
# Install Git with auto approval
yes | apt-get install git
# Check git install
git --version
Cloud Foundry CLI
See Install Cloud Foundry CLI Versions on the Harness Delegate.
Docker Installation
To install Docker on the Delegate, use the following script:
apt-get update
apt-get install -y apt-utils dnsutils docker
apt-get update
before running any apt-get
commands.PowerShell
You can run PowerShell scripts on a Harness Delegate, even though the Delegate must be run on Linux. Linux supports PowerShell using PowerShell core.
For steps on creating your script, see Installing PowerShell on Linux from Microsoft.
Whatever scripts you run must be supported by the version of PowerShell you install.
Here is an example for Ubuntu 16.04:
# Download the Microsoft repository GPG keys
wget -q https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb
# Register the Microsoft repository GPG keys
sudo dpkg -i packages-microsoft-prod.deb
# Update the list of products
sudo apt-get update
# Install PowerShell
sudo apt-get install -y powershell
# Start PowerShell
pwsh
If apt-get is not installed on your Delegate host, you can use snap (snap install powershell --classic
). See Install PowerShell Easily via Snap in Ubuntu 18.04.