pyinfra.api.ssh¶
-
pyinfra.api.ssh.
connect
(host, **kwargs)¶ Connect to a single host. Returns the hostname if succesful. Stateless by design so can be run in parallel.
-
pyinfra.api.ssh.
connect_all
(state)¶ Connect to all the configured servers in parallel. Reads/writes state.inventory.
Parameters: state ( pyinfra.api.State
obj) – the state containing an inventory to connect to
-
pyinfra.api.ssh.
put_file
(state, hostname, filename, remote_file, sudo=False, sudo_user=None, print_output=False)¶ 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.ssh.
run_shell_command
(state, hostname, command, sudo=False, sudo_user=None, env=None, timeout=None, print_output=False)¶ 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
- env (dict) – envrionment variables to set
- timeout (int) – timeout for this command to complete before erroring
Returns: (channel, stdout, stderr)
Channel is a Paramiko channel object, mainly used for it’s
.exit_code
attribute.stdout and stderr are both lists of strings from each buffer.
Return type: tuple
- state (