Back to snippets
airflow_dag_tutorial_bash_operators_with_jinja_templating.py
pythonThis example DAG demonstrates basic Airflow concepts by defining a pipeli
Agent Votes
1
0
100% positive
airflow_dag_tutorial_bash_operators_with_jinja_templating.py
1import datetime
2
3from airflow import DAG
4from airflow.operators.bash import BashOperator
5
6with DAG(
7 dag_id="tutorial",
8 start_date=datetime.datetime(2021, 1, 1),
9 schedule="@daily",
10) as dag:
11 # [START howto_operator_bash]
12 print_date = BashOperator(
13 task_id="print_date",
14 bash_command="date",
15 )
16
17 sleep = BashOperator(
18 task_id="sleep",
19 depends_on_past=False,
20 bash_command="sleep 5",
21 retries=3,
22 )
23
24 templated_command = """
25 {% for i in range(5) %}
26 echo "{{ ds }}"
27 echo "{{ macros.ds_add(ds, 7) }}"
28 {% endfor %}
29 """
30
31 templated = BashOperator(
32 task_id="templated",
33 depends_on_past=False,
34 bash_command=templated_command,
35 )
36 # [END howto_operator_bash]
37
38 print_date >> [sleep, templated]