You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using Airflow's SSHOperator and setting the command field to an absolute shell command (e.g., /bin/bash /home/user/test.sh), the DAG fails with a TemplateNotFound error. It appears that Airflow is treating the command string as a Jinja template file path.
Here is the error log:
[2025-07-03, 10:48:31] INFO - DAG bundles loaded: dags-folder: source="airflow.dag_processing.bundles.manager.DagBundlesManager"
[2025-07-03, 10:48:31] INFO - Filling up the DagBag from /home/airflow/airflow/dags/test_ssh_operator.py: source="airflow.models.dagbag.DagBag"
[2025-07-03, 10:48:31] ERROR - Failed to resolve template field 'command': source="airflow.sdk.definitions._internal.templater"
TemplateNotFound: '/bin/bash /home/user/test.sh' not found in search path: '/home/airflow/airflow/dags'
File "/home/airflow/airflow/venv/lib/python3.11/site-packages/airflow/sdk/definitions/_internal/templater.py", line 98 in resolve_template_files
File "/home/airflow/airflow/venv/lib/python3.11/site-packages/jinja2/loaders.py", line 209 in get_source
[2025-07-03, 10:48:31] ERROR - Exception rendering Jinja template for task 'test_ssh_operator', field 'command'. Template: '/bin/bash /home/user/test.sh': source="airflow.sdk.definitions._internal.abstractoperator"
TemplateNotFound: '/bin/bash /home/user/test.sh' not found in search path: '/home/airflow/airflow/dags'
File "/home/airflow/airflow/venv/lib/python3.11/site-packages/airflow/sdk/definitions/_internal/abstractoperator.py", line 379 in _do_render_template_fields
File "/home/airflow/airflow/venv/lib/python3.11/site-packages/airflow/sdk/definitions/_internal/templater.py", line 174 in render_template
File "/home/airflow/airflow/venv/lib/python3.11/site-packages/jinja2/environment.py", line 1016 in get_template
File "/home/airflow/airflow/venv/lib/python3.11/site-packages/jinja2/environment.py", line 975 in _load_template
File "/home/airflow/airflow/venv/lib/python3.11/site-packages/jinja2/loaders.py", line 126 in load
File "/home/airflow/airflow/venv/lib/python3.11/site-packages/jinja2/loaders.py", line 209 in get_source
[2025-07-03, 10:48:31] ERROR - Task failed with exception: source="task"
TemplateNotFound: '/bin/bash /home/user/test.sh' not found in search path: '/home/airflow/airflow/dags'
File "/home/airflow/airflow/venv/lib/python3.11/site-packages/airflow/sdk/execution_time/task_runner.py", line 832 in run
File "/home/airflow/airflow/venv/lib/python3.11/site-packages/airflow/sdk/execution_time/task_runner.py", line 752 in _prepare
File "/home/airflow/airflow/venv/lib/python3.11/site-packages/airflow/sdk/execution_time/task_runner.py", line 271 in render_templates
File "/home/airflow/airflow/venv/lib/python3.11/site-packages/airflow/sdk/bases/operator.py", line 1558 in render_template_fields
File "/home/airflow/airflow/venv/lib/python3.11/site-packages/airflow/sdk/definitions/_internal/abstractoperator.py", line 379 in _do_render_template_fields
File "/home/airflow/airflow/venv/lib/python3.11/site-packages/airflow/sdk/definitions/_internal/templater.py", line 174 in render_template
File "/home/airflow/airflow/venv/lib/python3.11/site-packages/jinja2/environment.py", line 1016 in get_template
File "/home/airflow/airflow/venv/lib/python3.11/site-packages/jinja2/environment.py", line 975 in _load_template
File "/home/airflow/airflow/venv/lib/python3.11/site-packages/jinja2/loaders.py", line 126 in load
File "/home/airflow/airflow/venv/lib/python3.11/site-packages/jinja2/loaders.py", line 209 in get_source
However, when I change the command to a simple command like "ls -l", or add some tails to the command like "/bin/bash /home/user/test.sh | tee output.log", the operator works without any issues.
I would like to know how to correctly use the SSHOperator to execute a shell script located at an absolute path on the remote server (e.g., /bin/bash /home/user/test.sh).
Is there a recommended way to pass such commands to the command field, so that Airflow does not treat them as Jinja template file paths?
Any guidance or best practices for this scenario would be greatly appreciated.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
When using Airflow's SSHOperator and setting the command field to an absolute shell command (e.g., /bin/bash /home/user/test.sh), the DAG fails with a TemplateNotFound error. It appears that Airflow is treating the command string as a Jinja template file path.
Here is the error log:
However, when I change the command to a simple command like "ls -l", or add some tails to the command like "/bin/bash /home/user/test.sh | tee output.log", the operator works without any issues.
I would like to know how to correctly use the SSHOperator to execute a shell script located at an absolute path on the remote server (e.g., /bin/bash /home/user/test.sh).
Is there a recommended way to pass such commands to the command field, so that Airflow does not treat them as Jinja template file paths?
Any guidance or best practices for this scenario would be greatly appreciated.
Here is my code:
My environment:
Beta Was this translation helpful? Give feedback.
All reactions