Reputation: 85
I set the variable with the "airflow variables
" command in cli
I wants to use this variable in DAG
.
I executed the following command on the terminal
The error continues occurs.
Broken DAG: [/root/airflow/dags/param_test.py] invalid syntax (param_test.py, line 13)
airflow variables -s sh_path = "/tmp/echo_test.sh"
airflow scheduler
here the code :
from airflow import DAG
from airflow.models import Variable
from airflow.operators.bash_operator import BashOperator
tmpl_search_path = Variable.get ("sh_path")
dag = DAG ('param_test', schedule_interval = '* / 5 * * * *'
start_date = datetime (2018,9,4), catchup = False)
bash_task = BashOperator (
task_id = "bash_task"
bash_command = 'sh '+ {{var.value.tmpl_search_path}},
dag = dag)
bash_task.set_downstream (python_task)
bash_task1 = BashOperator (
task_id = 'echo',
bash_command = 'echo 1',
dag = dag)
bash_task.set_downstream (bash_task1)
Upvotes: 4
Views: 14138
Reputation: 18894
You need to quote the jinja templating. Use it as below:
bash_task = BashOperator (
task_id = "bash_task"
bash_command = "sh {{var.value.tmpl_search_path}}",
dag = dag)
Upvotes: 4