airflow.providers.ssh.operators.ssh

Module Contents

Classes

SSHOperator

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

class airflow.providers.ssh.operators.ssh.SSHOperator(*, ssh_hook=None, ssh_conn_id=None, remote_host=None, command=None, conn_timeout=None, cmd_timeout=NOTSET, environment=None, get_pty=False, banner_timeout=30.0, skip_on_exit_code=None, **kwargs)[source]

Bases: airflow.models.BaseOperator

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

Parameters
  • ssh_hook (airflow.providers.ssh.hooks.ssh.SSHHook | None) – predefined ssh_hook to use for remote execution. Either ssh_hook or ssh_conn_id needs to be provided.

  • ssh_conn_id (str | None) – ssh connection id from airflow Connections. ssh_conn_id will be ignored if ssh_hook is provided.

  • remote_host (str | None) – remote 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.

  • command (str | None) – command to execute on remote host. (templated)

  • conn_timeout (int | None) – timeout (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_timeout (int | airflow.utils.types.ArgNotSet | None) – timeout (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.

  • environment (dict | None) – a dict of shell environment variables. Note that the server will reject them silently if AcceptEnv is not set in SSH config. (templated)

  • get_pty (bool) – request 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_timeout (float) – timeout to wait for banner from the server in seconds

  • skip_on_exit_code (int | Container[int] | None) – If command exits with this exit code, leave the task in skipped state (default: None). If set to None, any non-zero exit code will be treated as a failure.

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

property hook: airflow.providers.ssh.hooks.ssh.SSHHook[source]
template_fields: Sequence[str] = ('command', 'environment', 'remote_host')[source]
template_ext: Sequence[str] = ('.sh', '.bash', '.csh', '.zsh', '.dash', '.ksh')[source]
template_fields_renderers[source]
ssh_hook()[source]

Create SSHHook to run commands on remote host.

get_hook()[source]
get_ssh_client()[source]
exec_ssh_client_command(ssh_client, command)[source]
raise_for_status(exit_status, stderr, context=None)[source]
run_ssh_client_command(ssh_client, command, context=None)[source]
execute(context=None)[source]

Derive when creating an operator.

Context is the same dictionary used as when rendering jinja templates.

Refer to get_template_context for more context.

tunnel()[source]

Get ssh tunnel.

Was this entry helpful?