Basic usage

Fabric operators

Use FabricOperator to execute a command over SSH using the Fabric library, with e.g. a sudo password responder:

op = FabricOperator(
    task_id="example_fabric_task",
    dag_id="my_dag",
    ssh_conn_id="ssh_default",
    remote_host="my.remote.host",
    command="sudo ls -al ",
    add_sudo_password_responder=True
)

You can use a FabricHook instead of an ssh_conn_id:

hook = FabricHook(
    remote_host="my.remote.host",
    username="my.user",
    password="mypass"
)

op = FabricOperator(
    task_id="example_fabric_task",
    dag_id="my_dag",
    fabric_hook=hook,
    command="my_shell_script.sh"
)

Use a FabricSensor to wait until a command results in exit code 0:

op = FabricSensor(
    task_id="example_fabric_task",
    dag_id="my_dag",
    poke_interval=60,
    timeout=3600,
    mode="reschedule",
    ssh_conn_id="ssh_default",
    command="test -f {{ params.my_file" }} ",
    params={"my_file": "very_important_data.bin"}
)

Mattermost operator

Use MattermostWebhookOperator for a task that sends a message to an incoming Mattermost webhook.

The HTTP Connection that you specify with http_conn_id should contain a webhook_token in its extras field. Alternatively you can supply it in the operator:

op = MattermostWebhookOperator(
    task_id="example_mattermost_task",
    dag_id="my_dag",
    http_conn_id="http_mattermost",
    webhook_token="[webhook token]",
    message="Execution date: {{ ds }}"
)

You can also send a message without using a pre-defined Airflow Connection object, by specifying the complete webhook URL in the operator’s webhook_token:

op = MattermostWebhookOperator(
    task_id="example_mattermost_task",
    dag_id="my_dag",
    webhook_token="https://my.mattermost.host/[webhook token]",
    message="Something went wrong",
    icon_emoji=":boom:"
)

Conditional operators

Use ConditionalSkipMixin to add a Python condition to an operator. The task will be skipped if the condition evaluates to False. Example:

class MyConditionalOperator(ConditionalSkipMixin, MyOperator):
    template_fields = MyOperator.template_fields + ConditionalSkipMixin.template_fields
    ui_color = "#ff0000"

op = ConditionalTestOperator(
    task_id="example_conditional_task",
    dag_id="my_dag",
    condition_callable=lambda my_arg, **kwargs: kwargs["task_instance"].try_number == my_param
    condition_kwargs={"my_arg": 2},
    condition_provide_context=True
)

The mixin also works with sensors:

op = ConditionalBashSensor(
    task_id="example_conditional_task",
    dag_id="my_dag",
    poke_interval=60,
    timeout=3600,
    bash_command="test -f very_important_data.bin ",
    condition_callable=lambda my_arg, **kwargs: kwargs["task_instance"].try_number == my_param
    condition_args=[2],
    condition_provide_context=True
)

You can find several predefined conditional operators in modules conditional_operators and conditional_sensors.