VM deployments using SSH
Deploy artifacts to virtual machine or bare-metal hosts on any platform using Secure Shell (SSH).
You can use a Secure Shell (SSH) deployment type to deploy your artifacts to virtual machine (VM) or bare-metal hosts. These hosts can be in Microsoft Azure, Amazon Web Services (AWS), or any platform-agnostic Physical Data Center (PDC). This topic walks you through building an SSH deployment in Harness Continuous Delivery (CD), from the service and target infrastructure to the deployment strategy and rollback behavior.
What will you learn in this topic?
How to create a Secure Shell service and add an artifact source.
How to define the target infrastructure with pre-existing or dynamically provisioned hosts.
How to configure Basic, Rolling, and Canary executions and their looping strategies.
Deployment summary
An SSH deployment involves configuring the following:
Create a Harness Secure Shell service.
Set up a Harness connector to access your repository.
Define the target infrastructure for deployment.
Add the Harness connector for the target infrastructure.
Add the credentials needed to connect to target hosts.
Select the deployment strategy.
Run the pipeline and review.
SSH stages
To start an SSH deployment, create a new pipeline and add a stage for Secure Shell deployments.

Next, you create the service, environment, and execution steps for the stage.
SSH services
SSH services define the artifact you want to deploy and any config files you want to use.
In the stage Service tab, you add the artifact metadata and the related config files to execute on the target hosts.
Create a Harness Secure Shell service
Perform the following steps to create the service:
For Select Service, select New Service, and enter a name for the service.
For Service Definition, in Deployment Type, select Secure Shell.
Add the artifact connector
For Secure Shell, you can access artifacts from the following sources:
Harness Artifact Registry (Docker artifact type only)
Jenkins
Artifactory
Bamboo
Amazon S3
Amazon Elastic Container Registry (ECR)
Nexus2
Azure Artifacts
Google Container Registry (GCR)
GCR DEPRECATION
Google Container Registry (GCR) is being deprecated. Go to the deprecation notice to review the details.
Azure Container Registry (ACR)
Docker Registry (platform-agnostic)
Custom. If you select Custom, you must provide a Bash script.
The supported artifact package types include Docker, JAR, TAR, WAR, RPM, and ZIP.
Harness includes connectors for all the major artifact repositories. This example uses Artifactory and a publicly available artifact.
Perform the following steps to add the artifact connector:
In Artifacts, select Add Primary Artifact.
In Specify Artifact Repository Type, select the repository type.

Click to view full size image As an example, select Artifactory and select Continue. You can use another artifact repository if you prefer.
For the Artifactory Connector, select New Artifactory Connector.
In Name, enter a name for the connector and select Continue.
In Details, enter the following URL path for Artifactory Repository URL:
https://harness.jfrog.io/artifactory. This example uses the artifacts stored in that repository.For Authentication, select Anonymous and select Continue.

Click to view full size image Select Continue to connect with Artifactory by using a Harness Delegate.
In Delegates Setup, select Connect through the Harness Platform.
Select Save and Continue.
In Connection Test, Harness validates authentication and permissions for the repository.
Select Continue.

Set up artifact location and details
This example uses a publicly available ToDo List app artifact, todolist.war, available in a public Harness Artifactory repository.
In Artifact Details, perform the following steps:
In Artifact Source Name, enter Todolist.
In Repository Format, keep the default value Generic.
For Repository, enter todolist-tutorial. If you select Repository, Harness loads any available repositories and displays them for selection.
In Artifact Directory, enter a forward slash /.
In Artifact Details, keep the default Value.
In Artifact Path, leave the default runtime input value
<+input>for that field.Select Submit.

Click to view full size image The artifact is added to your service.

Click to view full size image Select Save. The service is added to your stage.
Select Continue to set up the target environment.
Define the target infrastructure
You define the target infrastructure for your deployment in the Environment settings of the pipeline stage. You can define an environment separately and select it in the stage, or create the environment within the stage Environment tab.
There are two methods of specifying the deployment target infrastructure:
Pre-existing: The target infrastructure already exists and you provide the required settings.
Dynamically provisioned: The target infrastructure is dynamically provisioned as part of the deployment process.
Go to Provisioning overview to understand Harness provisioning.
Select hosts
When you set up the Infrastructure Definition for the stage, there are three options for selecting the target hosts:
Specify hosts
Select preconfigured hosts from Physical Data Center
Map Dynamically Provisioned Infrastructure
Use Specify hosts or Select preconfigured hosts from Physical Data Center when you deploy to a pre-existing infrastructure. Use Map Dynamically Provisioned Infrastructure when you deploy to a dynamically provisioned infrastructure.
Filter hosts by attributes
This setting is available when you pick Select preconfigured hosts from Physical Data Center under Select hosts and select Filter by host attributes.
You can control whether multiple host-attribute filters are combined with OR (match any) or AND (match all) logic:
Any (default): A host is selected if at least one filter condition matches. This is the existing behavior.
All: A host is selected only if every filter condition matches.
For Specific Attribute, you specify the condition that the match criteria is checked against. You can specify attributes such as region, type, and name.
Under Preview Hosts, you can see which hosts match the condition.

Pre-existing infrastructure
This example sets up an Infrastructure Definition for a pre-existing infrastructure.
Perform the following steps to set up the infrastructure:
In Specify Environment, select or create an environment.
In the environment, in Specify Infrastructure, select New infrastructure.
Enter a name for the new infrastructure.
For Select Infrastructure Type, select where you want to deploy. This example uses Physical Data Center.
Keep the default selection, Physical Data Center.

Click to view full size image
Target specific hosts for deployment
You can pass in specific host IPs to perform deployment in the SSH Infrastructure Definition. When your deployment stage deploys a Secure Shell (SSH) service or a Windows Remote Management (WinRM) service using an Infrastructure Definition of deployment type SSH or WinRM, you can select target hosts that were not selected in the stage's Infrastructure Definition. Harness presents a dropdown in the Pipeline Run form with the queried list of host names.
Create the PDC connector for the hosts
Perform the following steps to create the Physical Data Center (PDC) connector:
In Infrastructure Definition, for Connector, select Select Connector to create the connector for the PDC.
In Create or Select an Existing Connector, select New Connector.
In Physical Data Center, enter a name for this connector, such as PDC-Connector.
Select Continue.
In Details, keep the default for Manually enter host names and enter the hostnames for the target instances.
Select Continue.
In Delegates Setup, keep the default for Use any available Delegate.
Select Save and Continue. Harness validates connectivity for the PDC connector.
Select Finish. The Infrastructure Definition is updated with the PDC connector.

Use an SSH credential to authenticate to target hosts
You can use an SSH key or Kerberos to authenticate to the target hosts. This example uses an SSH key.
Perform the following steps to create the SSH credential:
In Specify Credentials, select Create or Select a Secret.
In Create or Select an Existing Secret, select New SSH Credential.
In SSH Details, for Name, enter a name for this SSH credential and select Continue.
In Configuration and Authentication, there are three authentication options. This example uses Username/SSH Key. Select the dropdown menu and select Username/SSH Key.
Enter a username, such as ec2-user.
For Select or create a SSH Key, select Create or Select a Secret.
In Create or Select an Existing Secret, select New Secret File.
In Add new Encrypted File, enter a name for Secret Name, such as ssh-key-name. This is the name you use to reference this file.
For Select File, select Browse. On your machine, select the secret file that you downloaded from your instance. For EC2, use the .pem file.
Select Save.
In Configuration and Authentication, keep the default values for Passphrase and SSH port. Select Save and Continue.
In Verify Connection, enter the hostname for the instance in the Add a Host Name to start verification field and select Connection Test.
The Secure Shell connection to the instance is tested. Select Finish. Select Continue.
You can use the Preview Hosts section to test the connection at any time.
Select Save.
Back in Environment, select Continue.
Next, you select the deployment strategy for this stage, the package type, and the number of instances to deploy on.
Dynamically provisioned infrastructure
Harness supports multiple provisioner types, including Terraform, CloudFormation, Shell Script, and so on. Go to Provision Infrastructure to explore the available provisioners and configure provisioning based on your requirements.
The following is a summary of the steps to dynamically provision the target infrastructure for a deployment:
Add dynamic provisioning to the CD stage:
In a Harness Deploy stage, in Environment, enable the option Provision your target infrastructure dynamically during the execution of your Pipeline.
Select the type of provisioner that you want to use.
Harness automatically adds the provisioner steps for the provisioner type you selected.
Configure the provisioner steps to run your provisioning scripts.
Select or create a Harness infrastructure in Environment.
Map the provisioner outputs to the Infrastructure Definition:
In the Harness infrastructure, enable the option Map Dynamically Provisioned Infrastructure.
Map the provisioning script or template outputs to the required infrastructure settings.
Supported provisioners
The following provisioners are supported for SSH deployments:
Terraform
Terragrunt
Terraform Cloud
CloudFormation
Azure Resource Manager (ARM)
Azure Blueprint
Shell Script
Add dynamic provisioning to the stage
Perform the following steps to add dynamic provisioning to a Harness pipeline Deploy stage:
In a Harness Deploy stage, in Environment, enable the option Provision your target infrastructure dynamically during the execution of your Pipeline.
Select the type of provisioner that you want to use.
Harness automatically adds the necessary provisioner steps.
Set up the provisioner steps to run your provisioning scripts.
For documentation on each of the required steps for the provisioner you selected, go to the following topics:
Terraform:
Go to Terraform Plan to configure the plan step.
Go to Terraform Apply to configure the apply step.
Go to Terraform Rollback to configure the rollback step. To see the Terraform Rollback step, toggle the Rollback setting.
Go to Terragrunt to configure Terragrunt provisioning.
Go to Terraform Cloud to configure Terraform Cloud provisioning.
CloudFormation:
Go to Create Stack to configure the create step.
Go to Delete Stack to configure the delete step.
Go to Rollback Stack to configure the rollback step. To see the Rollback Stack step, toggle the Rollback setting.
Go to Azure Resource Manager (ARM) to configure ARM provisioning.
Go to Azure Blueprint to configure Blueprint provisioning.
Go to Shell Script to configure Shell Script provisioning.
Map provisioner output
Once you set up dynamic provisioning in the stage, you must map outputs from your provisioning script or template to specific settings in the Harness Infrastructure Definition used in the stage.
Perform the following steps to map the provisioner output:
In the same CD Deploy stage where you enabled dynamic provisioning, select or create (New Infrastructure) a Harness infrastructure.
In the Harness infrastructure, in Select Infrastructure Type, select Physical Data Center, Azure, or AWS.
In Select Hosts/Azure/Amazon Web Services Infrastructure Details, enable the option Map Dynamically Provisioned Infrastructure.
A Provisioner setting is added and configured as a runtime input.
Map the provisioning script or template outputs to the required infrastructure settings.
To provision the target deployment infrastructure, Harness needs specific infrastructure information from your provisioning script. You provide this information by mapping specific Infrastructure Definition settings in Harness to outputs from your template or script.
For SSH infrastructures, Harness needs the following settings mapped to outputs:
Physical Data Center (PDC):
Host Array Path
Host Data Mapping: Map outputs for all of the necessary connection information. For example, for VMs on a cloud platform:
hostname
privateIp
subnetId
region
Azure:
Subscription Id
Resource Group
Tag (optional)
AWS:
Region
Tag (optional)
Host array path variable
For SSH PDC deployments, you use the expression <+provisioner.OUTPUT_NAME> for the Host Array Path setting.
For the subsequent Host Data Mapping key-value pairs, you use the expression format <+HOST_PROPERTY>. For example, <+public_dns>.
The following is an example:

Example Terraform script
The following is a snippet of a Terraform script that provisions the infrastructure for an AWS EC2 VM SSH deployment and includes the required outputs for Physical Data Center:
In the Harness Infrastructure Definition, you map outputs to their corresponding settings using expressions in the format <+provisioner.OUTPUT_NAME>, such as <+provisioner.region>.

Reference mapped instance properties
Once you have mapped provisioning script outputs to the stage Infrastructure Definition, you can reference them in Execution of the stage.
To reference a mapped output, you use an expression in the format <+instance.properties.*>.
For example, here are some Host Data Mapping keys and expressions that reference them:
hostname:
<+instance.properties.hostname>privateIp:
<+instance.properties.privateIp>subnetId:
<+instance.properties.subnetId>region:
<+instance.properties.region>
SSH executions
In Execution, Harness automatically adds the steps required to deploy the service to the environment according to the deployment strategy you select.
The execution strategies supported for Secure Shell include Blank Canvas, Basic, Rolling, and Canary. This example uses Basic.
Basic deployments
Perform the following steps to configure a Basic deployment:
In Execution Strategies, select Basic. Typically, you use Basic when deploying to one host, and Rolling or Canary for multiple hosts.
For Package type, select WAR.
Select Use Strategy. Harness adds the Deploy step for execution.
Select the Deploy step. Here is where you add the scripts for your package. This example uses the defaults and copies the artifact to the target host.

Click to view full size image In Command Scripts, edit Copy Config.
In Edit Command, for Select file type to copy, select Artifact.

Click to view full size image Select Save.
Review the looping strategy. The looping strategy repeats deployments for multiple hosts and for different deployment strategies (Basic, Rolling, Canary).
Select Advanced.
Select Looping Strategy. The step is repeated for all hosts using the
<+stage.output.hosts>expression. For example, if you had two hosts, the step would be repeated for each host.

Click to view full size image Select Apply Changes.
When you are done, select Save to publish the pipeline.
Deploy and review
The following is an example SSH deployment.
Perform the following steps to run and review the deployment:
Select Run to run the pipeline.
In Run Pipeline, for Primary Artifact, select Todolist.
In Artifact Path, Harness displays a list of available artifact packages.
Select todolist.war.

Click to view full size image Select Run Pipeline. Harness runs the pipeline, and the Console View displays the tasks executed for each step.
Review deployment
Review what happens in the Deploy step. Most sections correspond to the commands you can see in the Deploy step:
Initialize: Initialize the connection to the hosts and create a temp directory for the deployment.
Setup Runtime Paths: Create folders for runtime, backup, and staging.
Copy Artifact: Copy the artifact to the host.
Copy Config: Copy the config files (if any) to the host.
Cleanup: Remove temp directories.
You have now created and completed the steps for running a pipeline by using Secure Shell.
Selective rerun and skip hosts with the same artifact
You can skip the hosts where the last deployment was successful using the same artifact for traditional deployments. These improvements provide:
Efficient reruns: Redeploy only on failed hosts instead of all hosts.
Expressions for failed hosts: Retrieve failed hosts dynamically for debugging, fixing, and rerunning on only failed hosts.
To use this feature, go to the Advanced tab of the CD stage and enable the Skip instances with the same artifact version already deployed checkbox.
You can enable this checkbox at runtime by making the checkbox a Runtime Input.

Success criteria for deployment on a host
Successfully deployed criteria: A host is considered successfully deployed only if all command steps in an execution complete successfully.
Deployed criteria: A host is considered deployed if any command step execution occurs on the host.
Key features
1. Selective retry for failed hosts
Deployment retries target only failed hosts instead of redeploying on all hosts when the Skip instances with the same artifact version already deployed checkbox is enabled.
2. Enhanced skip instances feature
Deployment is skipped on hosts where the last deployment was successful using the same artifact.
Each host's deployment success is tracked individually, ensuring that only failed hosts are retried.
Infrastructure changes (for example, connector updates or credential changes) are considered when determining the last deployment on a host.
3. Improved rollback behavior
The skip instances feature tracks rollbacks per host, ensuring that only the required hosts are updated.
This guarantees that rollback logic applies only to affected hosts, preventing unnecessary redeployments.
4. New expressions introduced
These expressions provide better tracking of deployment and skipped instances:
<+stage.output.skippedHosts>: Fetches hosts skipped during the current deployment via the skip instances feature.<+stageFqn.deployedHosts.succeeded>: Fetches hosts that successfully deployed in a stage.<+stageFqn.deployedHosts.failed>: Fetches hosts that failed deployment in a stage.
Permissions for SSH deployments in AWS
Harness uses the SSH credentials to connect to hosts to perform deployment.
Harness uses the AWS connector to retrieve instances from the AWS account. Harness makes the following calls:
Retrieve the instances at runtime during the infrastructure step: DescribeInstances.
Retrieve the instances during instance sync to show service instances in the service: DescribeInstances.
To use the describe instance API, the action is ec2:DescribeInstances.
Per AWS documentation, go to Example policies for working with the AWS CLI or an AWS SDK to review Amazon Elastic Compute Cloud policy examples.
Additional deployment configuration
Select multiple hosts
You can add multiple hosts in the Physical Data Center connector.

During deployment, you see each host listed in the loop.

Looping strategies for each deployment strategy
The Repeat looping strategy is used differently for the Basic, Rolling, and Canary deployment types.
The looping strategy is automatically added to the Deploy step and configured for the deployment type you selected.

The following sections describe how the looping strategy is used for different deployment types.
Basic
The looping strategy for the Basic deployment repeats the deployment on all the target hosts.
Rolling
For a Rolling strategy, you specify how many instances you want to deploy per phase.
Suppose you have 10 target hosts in the stage Infrastructure Definition and you want to have 3 instances per phase.
In Instances, you enter 3.
As a result, when execution starts there are 4 phases: 3, 3, 3, 1. The number of instances per phase can be provided as a count or a percentage.
The following is an example of the Rolling strategy using 2 hosts with 50% in Instances.

Harness rolls out to 50% of target hosts first, and then the remaining 50% if the first 50% were successful.
Harness creates 2 phases.

You can add any Approval steps inside the Phase Group. Go to Approvals to configure approval steps.
The looping strategy for the first phase deploys to 50% of the hosts (partitions):
The looping strategy for the second phase repeats the partition count:
The <+repeat.partition> expression resolves how many instances (items) to iterate over per one partition (phase).
Suppose you have 10 hosts and 4 partitions organized as 3, 3, 3, 1. The first partition includes 3 hosts, the second and third each have 3, and the last one has 1 host.
So, partition1 = host1, host2, host3, partition2 = host4, host5, host6, partition3 = host7, host8, host9, and partition4 = host10.
Canary
For Canary strategies, Harness calculates phase instances based on the number of hosts and the number of requested instances per phase.
Suppose you have 10 hosts and you add 2 phases with 50% and 100%. Harness deploys on 5 instances in the first phase and on the rest of the instances in the second phase.
The following is an example of the Canary strategy using 2 hosts and 2 phases. The first phase deploys to 50% and the second phase deploys to 100%.

Harness rolls out to 50% of target hosts first, and then the remaining 50% if the first 50% were successful.
Harness creates 2 phases as step groups.

You can add any Approval steps between the step groups. Go to Harness approval steps in CD stages, Jira approval stages, and ServiceNow approvals to configure approvals.
The looping strategy for the first phase selects 50% of the target hosts:
The looping strategy for the second phase starts at the 50% from the first phase and continues to 100%:
Control deployments after a host failure
To control what happens after one iteration fails, add the onFailure field at the strategy level, alongside your matrix or repeat configuration. The onFailure field accepts two values:
RunAll: Run all remaining iterations even if one fails. This is the default behavior.SkipQueued: Skip any iterations that have not started once one iteration fails.
The following example uses SkipQueued to skip the remaining hosts after a failure. Because maxConcurrency is 1, hosts deploy one at a time, so a failure stops the loop:
SkipQueued skips only hosts that have not started deploying. Hosts already deploying continue to completion. To stop deployments as early as possible, set maxConcurrency: 1.
Reference hosts in steps with expressions
You can use the following instance expressions to reference your hosts.
Microsoft Azure or Physical Data Center
<+instance.hostName><+instance.host.hostName><+instance.name>
Microsoft Azure and AWS
<+instance.host.privateIp><+instance.host.publicIp>
Rollback
Harness restores the state of deployment to the pipeline's previous successful stage execution based on service, environment, and infrastructure details.
Harness records the artifact version that was successfully deployed during previous successful executions. When using the Rollback step's Copy Artifact command unit, Harness copies the last successful version of the artifact deployed via Harness to the remote host.
First-time deployment
If the first pipeline execution fails (regardless of stage), Harness skips the rollback since there is no record of any successful pipeline execution.
N+1 time deployment
In case of stage failures in subsequent executions (assuming the service, environment, and infrastructure did not change in the corresponding stage), Harness initiates rollback to the previous successful pipeline. The previous pipeline execution must be successful for all stages. The successful stage is matched regardless of the pipeline execution status.
Go to Use Harness expressions to reference deployment details.
FAQs
Go to SSH and WinRM deployment FAQs to review frequently asked questions about traditional deployments in Harness.
Next steps
You have created an SSH deployment, defined the target infrastructure, and configured the deployment strategy and rollback behavior. Continue with the following topics:
Provisioning overview: Dynamically provision target infrastructure.
Use Harness expressions: Reference hosts and instance properties.
Last updated
Was this helpful?