pyinfra.api.connectors.ssh module

class pyinfra.api.connectors.ssh.WarningPolicy

Bases: paramiko.client.MissingHostKeyPolicy

missing_host_key(client, hostname, key)

Called when an .SSHClient receives a server key for a server that isn’t in either the system or local .HostKeys object. To accept the key, simply return. To reject, raised an exception (which will be passed to the calling application).

pyinfra.api.connectors.ssh.check_can_rsync(host)
pyinfra.api.connectors.ssh.connect(state, host)

Connect to a single host. Returns the SSH client if succesful. Stateless by design so can be run in parallel.

pyinfra.api.connectors.ssh.get_file(state, host, remote_filename, filename_or_io, sudo=False, sudo_user=None, su_user=None, print_output=False, print_input=False, **command_kwargs)

Download a file from the remote host using SFTP. Supports download files with sudo by copying to a temporary directory with read permissions, downloading and then removing the copy.

pyinfra.api.connectors.ssh.make_names_data(hostname)
pyinfra.api.connectors.ssh.put_file(state, host, filename_or_io, remote_filename, sudo=False, sudo_user=None, su_user=None, print_output=False, print_input=False, **command_kwargs)

Upload file-ios to the specified host using SFTP. Supports uploading files with sudo by uploading to a temporary directory then moving & chowning.

pyinfra.api.connectors.ssh.rsync(state, host, src, dest, flags, print_output=False, print_input=False, sudo=False, sudo_user=None, **ignored_kwargs)
pyinfra.api.connectors.ssh.run_shell_command(state, host, command, get_pty=False, timeout=None, stdin=None, success_exit_codes=None, print_output=False, print_input=False, return_combined_output=False, use_sudo_password=False, **command_kwargs)

Execute a command on the specified host.

Parameters
  • state (pyinfra.api.State obj) – state object for this command
  • hostname (string) – hostname of the target
  • command (string) – actual command to execute
  • sudo (boolean) – whether to wrap the command with sudo
  • sudo_user (string) – user to sudo to
  • get_pty (boolean) – whether to get a PTY before executing the command
  • env (dict) – environment variables to set
  • timeout (int) – timeout for this command to complete before erroring
Returns

(exit_code, stdout, stderr) stdout and stderr are both lists of strings from each buffer.

Return type

tuple