Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Airflow BashOperator can't find Bash

Tags:

python

airflow

I'm using Airflow in Centos 7, using Python 3.7.

When I run a Bash command through BashOperator, I run in to the following problem:

[2019-11-13 23:20:08,238] {taskinstance.py:1058} ERROR - [Errno 2] No such file or directory: 'bash': 'bash'
Traceback (most recent call last):
  File "/home/airflow/virtualenvs/airflow_env/lib/python3.7/site-packages/airflow/models/taskinstance.py", line 930, in _run_raw_task
    result = task_copy.execute(context=context)
  File "/home/airflow/virtualenvs/airflow_env/lib/python3.7/site-packages/airflow/operators/bash_operator.py", line 120, in execute
    preexec_fn=pre_exec)
  File "/home/airflow/python/Python-3.7.5/Lib/subprocess.py", line 800, in __init__
    restore_signals, start_new_session)
  File "/home/airflow/python/Python-3.7.5/Lib/subprocess.py", line 1551, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'bash': 'bash'

Is there a variable I need to pass to BashOperator so it knows to look for /bin/bash? In the source code, it appears that BashOperator opens a subprocess using bash; do I need to modify it to use /bin/bash?

like image 765
ohss117 Avatar asked Aug 04 '26 09:08

ohss117


1 Answers

It turns out I had to modify PATH variable in my systemctl file.

Adding :/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin to PATH fixed my problem.

My setup is using Airflow + virtualenv managed through Systemctl on Centos 7.

Airflow scheduler systemctl file

[Unit]
Description=Airflow scheduler daemon
After=network.target postgresql.service mysql.service redis.service rabbitmq-server.service
Wants=postgresql.service mysql.service redis.service rabbitmq-server.service

[Service]
EnvironmentFile=/etc/sysconfig/airflow
Environment=VIRTUAL_ENV=/home/airflow/virtualenvs/airflow_env
Environment=PATH=/home/airflow/virtualenvs/airflow_env/bin:$PATH:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin
User=airflow
Group=airflow
Type=simple
ExecStart=/home/airflow/virtualenvs/airflow_env/bin/airflow scheduler
Restart=always
RestartSec=5s
RuntimeDirectory=airflow
RuntimeDirectoryMode=0775

[Install]
WantedBy=multi-user.target
like image 114
ohss117 Avatar answered Aug 06 '26 21:08

ohss117



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!