Skip to content

SSH SSH: Client

Summary

This module contains actions for running commands on an SSH device, & uploading files over SCP.

Before you Start

See Running Commands before using actions in this plugin.

Actions

ssh.client.

run_command

Run a non-interactive command.

Minimum Plugin Version: 1.0.0

Input
  • ssh_server: an SSHPasswordAuth or SSHKeyAuth dictionary

  • command: the command to run

  • prompt_timeout: the number of seconds to wait for the command to complete (defaults to 5)

  • connection_timeout: the number of seconds to wait for the connection to establish (defaults to 10)

Output

A string containing any command output.

Example
1
2
3
4
5
- ssh.client.run_command:
    command: ls --color=never -lsah
  load:
    ssh_server: ssh_server
  save: directory_listing

ssh.client.

run_commands

Run multiple commands in the same SSH session.

Use questions to handle any interactive prompts the command may trigger.

Minimum Plugin Version: 1.0.0

Input
  • ssh_server: an SSHPasswordAuth or SSHKeyAuth dictionary

  • commands: a list of Command dictionaries

  • prompt_timeout: the number of seconds to wait for commands to complete (defaults to 5)

  • connection_timeout: the number of seconds to wait for the connection to establish (defaults to 10)

Output

A list of strings containing the sequential output from each command.

Example 1 - Non-Interactive Commands
1
2
3
4
5
6
7
8
- ssh.client.run_commands:
    commands:
      - command: date
      - command: uptime
      - command: lsb_release -c
  load:
    ssh_server: ssh_server
  save: server_check
Example 2 - Password Prompt
1
2
3
4
5
6
7
8
9
- ssh.client.run_commands:
    commands:
      - command: sudo ls -lsah --color=never
        questions:
          - prompt: "\\[sudo\\] password for .*"
            answer: "{{ ssh_server.password }}"
  load:
    ssh_server: ssh_server
  save: directory_listing

ssh.client.

scp_upload_from_text

Upload some text as a file to an SCP server.

Minimum Plugin Version: 1.1.0

Input
  • scp_server: an SCPServer dictionary

  • file_contents: the contents of the text file

  • destination: the destination path on the SCP server (must include the file name)

Output

Nothing is outputted by this action.

Example
1
2
3
4
5
6
- ssh.client.scp_upload_from_text:
    file_contents: >
      This will be uploaded as a text file.
    destination: /home/ppa/text-file.txt
  load:
    ssh_server: ssh_server