Execute commands on remote servers via SSH using the cloudbees-io/ssh-deploy-actions action.
| All CloudBees action repositories are listed at CloudBees, Inc. on GitHub. |
Inputs
| Input name | Data type | Required? | Description |
|---|---|---|---|
|
String |
Yes |
SSH host address. |
|
String |
Yes |
The SSH username. |
|
String |
Yes |
The commands to be executed. |
|
String |
Required only if |
The path to the SSH private key file. |
|
String |
Required only if |
The SSH password. |
|
String |
No |
SSH port number.
Default is |
|
String |
No |
The SSH key passphrase. |
Usage examples
The following examples show how to connect using an SSH private key, a password, a passphrase-protected key, and Chef knife commands.
Execute remote commands using an SSH private key
In your YAML file, add:
- name: SSH with username and key uses: https://github.com/cloudbees-io/ssh-deploy-actions@v1 with: host: ${{ secrets.SSH_HOST }} username: user1 key_path: ${{ secrets.SSH_PRIVATE_KEY }} port: "22" script: whoami,pwd,echo "hello"
Execute remote commands using a password
In your YAML file, add:
- name: SSH with username and password uses: https://github.com/cloudbees-io/ssh-deploy-actions@v1 with: host: ${{ secrets.SSH_HOST }} username: testUser password: ${{ secrets.SSH_PASSWORD }} port: "22" script: whoami,pwd
Execute remote commands using a passphrase-protected key
In your YAML file, add:
- name: SSH with username and passphrase-protected key uses: https://github.com/cloudbees-io/ssh-deploy-actions@v1 with: host: ${{ secrets.SSH_HOST }} username: demoUser key_path: ${{ secrets.SSH_PP_KEY }} port: "22" passphrase: ${{ secrets.SSH_PP_KEY_PASSPHRASE }} script: pwd,echo "hello"
Execute Chef knife commands and trigger cookbooks
Chef is an open-source configuration management tool that automates infrastructure provisioning and management by defining system configurations as code. Use SSH access to the Chef workstation to execute knife commands and trigger cookbooks on the Chef nodes.
| The CloudBees Unify user must provide a single workstation with pre-configured roles, a configured knife bootstrap, and a configured SSH connection. The communication between the workstation, server, and nodes must be verified and tested before use. |
In your YAML file, add:
- name: Execute remote Chef commands uses: https://github.com/cloudbees-io/ssh-deploy-actions@v1 with: host: ${{ secrets.MY_SSH_HOST }} username: ${{ secrets.CHEF_WS_USER }} key_path: ${{ secrets.CHEF_WS_KEY }} port: "22" script: cd chef-repo/ && sudo knife ssh "name:*" 'sudo chef-client -o "recipe[nano_install]"' -x ec2-user -p 22 -i chefnode.pem
The following command logs in to the Chef nodes and runs the chef-client command, which executes the cookbook:
`sudo knife ssh "name:*" 'sudo chef-client -o "recipe[nano_install]"' -x ec2-user -p 22 -i chefnode.pem`
For more information, refer to the Chef knife SSH documentation.