airflow.providers.ssh.operators.ssh

Module Contents

Classes

SSHOperator

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

Attributes

CMD_TIMEOUT

airflow.providers.ssh.operators.ssh.CMD_TIMEOUT = 10[source]
class airflow.providers.ssh.operators.ssh.SSHOperator(*, ssh_hook: Optional[airflow.providers.ssh.hooks.ssh.SSHHook] = None, ssh_conn_id: Optional[str] = None, remote_host: Optional[str] = None, command: Optional[str] = None, timeout: Optional[int] = None, conn_timeout: Optional[int] = None, cmd_timeout: Optional[int] = None, environment: Optional[dict] = None, get_pty: bool = False, **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) -- predefined ssh_hook to use for remote execution. Either ssh_hook or ssh_conn_id needs to be provided.

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

  • remote_host (str) -- 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) -- command to execute on remote host. (templated)

  • conn_timeout (int) -- 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) -- timeout (in seconds) for executing the command. The default is 10 seconds.

  • timeout (int) -- (deprecated) timeout (in seconds) for executing the command. The default is 10 seconds. Use conn_timeout and cmd_timeout parameters instead.

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

  • 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.

template_fields :Sequence[str] = ['command', 'remote_host'][source]
template_ext :Sequence[str] = ['.sh'][source]
template_fields_renderers[source]
get_hook(self) airflow.providers.ssh.hooks.ssh.SSHHook[source]
get_ssh_client(self) paramiko.client.SSHClient[source]
exec_ssh_client_command(self, ssh_client: paramiko.client.SSHClient, command: str) Tuple[int, bytes, bytes][source]
raise_for_status(self, exit_status: int, stderr: bytes) None[source]
run_ssh_client_command(self, ssh_client: paramiko.client.SSHClient, command: str) bytes[source]
execute(self, context=None) Union[bytes, str][source]

This is the main method to 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(self) None[source]

Get ssh tunnel

Was this entry helpful?