simplycoding
simplycoding

Reputation: 2967

How do I set an environment variable for airflow to use?

Airflow is returning an error when trying to run a DAG saying that it can't find an environment variable, which is odd because it's able to find 3 other environment variables that I'm storing as a Python variable. No issues with those variables at all.

I have all 4 variables in ~/.profile and have also done

export var1="varirable1"
export var2="varirable2"
export var3="varirable3"
export var4="varirable4"

Under what user does airflow run? I've done those export commands under sudo as well, so I thought they would be picked up by airflow when it runs the dag

Upvotes: 6

Views: 18306

Answers (3)

Tomasz Zielański
Tomasz Zielański

Reputation: 473

As per this answer, the variables should be put in /etc/default/airflow (on Debian/Ubuntu) or /etc/sysconfig/airflow (on Centos/Redhat).

Upvotes: 1

qfwfq
qfwfq

Reputation: 2516

If you are just running a local instance you should be able to use environment variables like you expect. Remember that you need to set them in the shell that is running the webserver and scheduler though. If these are in your .profile, you may need to run source ~/.profile.

Upvotes: 0

Breathe
Breathe

Reputation: 724

Is it maybe because airflow uses non-login shell? Have you tried putting these lines in : ~/.bashrc instead of ~/.profile ?

Upvotes: 3

Related Questions