Documentation Index
Fetch the complete documentation index at: https://mintlify.com/pyinfra-dev/pyinfra/llms.txt
Use this file to discover all available pages before exploring further.
Execute commands and up/download files from the remote host.
Eg: pyinfra -> inventory-host.net <-> another-host.net
Functions
ssh.keyscan
Check/add hosts to the ~/.ssh/known_hosts file.
ssh.keyscan(
hostname,
force=False,
port=22,
)
ssh.command
Execute commands on other servers over SSH.
ssh.command(
hostname,
command,
user=None,
port=22,
)
ssh.upload
Upload files to other servers using scp.
ssh.upload(
hostname,
filename,
remote_filename=None,
port=22,
user=None,
use_remote_sudo=False,
ssh_keyscan=False,
)
ssh.download
Download files from other servers using scp.
ssh.download(
hostname,
filename,
local_filename=None,
force=False,
port=22,
user=None,
ssh_keyscan=False,
)
Examples
from pyinfra.operations import ssh
# Add a host to known_hosts
ssh.keyscan(
name="Set add server two to known_hosts on one",
hostname="two.example.com",
)
# Execute a command on another server
ssh.command(
name="Create file by running echo from host one to host two",
hostname="two.example.com",
command="echo 'one was here' > /tmp/one.txt",
user="vagrant",
)
# Upload a file to another server
ssh.upload(
name="Upload file to another server",
hostname="two.example.com",
filename="/tmp/myfile.txt",
remote_filename="/tmp/remote_file.txt",
)