SSHOperator

SSH

SSHOperator to execute commands on given remote host using the ssh_hook.

View on GitHub

Last Updated: Mar. 21, 2023

Access Instructions

Install the SSH provider package into your Airflow environment.

Import the module into your DAG file and instantiate it with your desired params.

Parameters

ssh_hookpredefined ssh_hook to use for remote execution. Either ssh_hook or ssh_conn_id needs to be provided.
ssh_conn_idssh connection id from airflow Connections. ssh_conn_id will be ignored if ssh_hook is provided.
remote_hostremote host to connect (templated) Nullable. If provided, it will replace the remote_host which was defined in ssh_hook or predefined in the connection of ssh_conn_id.
commandcommand to execute on remote host. (templated)
conn_timeouttimeout (in seconds) for maintaining the connection. The default is 10 seconds. Nullable. If provided, it will replace the conn_timeout which was predefined in the connection of ssh_conn_id.
cmd_timeouttimeout (in seconds) for executing the command. The default is 10 seconds. Nullable, None means no timeout. If provided, it will replace the cmd_timeout which was predefined in the connection of ssh_conn_id.
environmenta dict of shell environment variables. Note that the server will reject them silently if AcceptEnv is not set in SSH config. (templated)
get_ptyrequest a pseudo-terminal from the server. Set to True to have the remote process killed upon task timeout. The default is False but note that get_pty is forced to True when the command starts with sudo.
banner_timeouttimeout to wait for banner from the server in seconds

Documentation

SSHOperator to execute commands on given remote host using the ssh_hook.

If do_xcom_push is True, the numeric exit code emitted by the ssh session is pushed to XCom under key ssh_exit.

Was this page helpful?