# How to configure environment variables for dbtoperator

**URL:** <https://discourse.getdbt.com/t/how-to-configure-environment-variables-for-dbtoperator/6316>\
**Category:** Help\
**Tags:** bigquery, airflow, orchestration-and-deployment\
**Created:** [January 24, 2023, 11:34am UTC](https://discourse.getdbt.com/t/how-to-configure-environment-variables-for-dbtoperator/6316 "2023-01-24T11:34:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![III](https://avatars.discourse-cdn.com/v4/letter/i/ecb155/32.png) [@III](https://discourse.getdbt.com/u/III)\
**Post date:** [January 24, 2023, 11:34am UTC](https://discourse.getdbt.com/t/how-to-configure-environment-variables-for-dbtoperator/6316/1 "2023-01-24T11:34:52Z")

</div>

## The problem I’m having

Can’t run dbt model in airflow due to missing environment variables.

## The context of why I’m trying to do this

Setup of environment variables in airfow dag using dbtoperator([GitHub - gocardless/airflow-dbt: Apache Airflow integration for dbt](https://github.com/gocardless/airflow-dbt))

## What I’ve already tried

1. using env in the default \_args

## Some example code or error messages

```auto
from airflow import DAG
from airflow.operators.bash import BashOperator
from airflow_dbt.operators.dbt_operator import DbtRunOperator

default_args = {
'dir': '/opt/airflow/dbt',
'profiles_dir': '/opt/airflow/dbt',
'owner': 'airflow',
}

with DAG(dag_id='example', default_args=default_args, schedule_interval=None) as dag:

    dbt_run= DbtRunOperator(
    task_id='dbt_run',
    select='/opt/airflow/dbt/models/core/example.sql'
    )
    
    dbt_run

```

---

<div class="post-metadata">

**Author:** ![wefo](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/wefo/32/1632_2.png) [@wefo](https://discourse.getdbt.com/u/wefo)\
**Post date:** [January 24, 2023, 1:27pm UTC](https://discourse.getdbt.com/t/how-to-configure-environment-variables-for-dbtoperator/6316/2 "2023-01-24T13:27:47Z")

</div>

Hey @III

Based on airflow-dbt documentation, operators accept multiple arguments, including `target`.

Have you tried this:

```auto
    dbt_run= DbtRunOperator(
        task_id='dbt_run',
        select='/opt/airflow/dbt/models/core/example.sql',
        target=[YOUR_TARGET_NAME]
    )

```

---

<div class="post-metadata">

**Author:** ![III](https://avatars.discourse-cdn.com/v4/letter/i/ecb155/32.png) [@III](https://discourse.getdbt.com/u/III)\
**Post date:** [January 24, 2023, 3:42pm UTC](https://discourse.getdbt.com/t/how-to-configure-environment-variables-for-dbtoperator/6316/3 "2023-01-24T15:42:07Z")

</div>

Thanks, this can now be marked as resolved.

---

<div class="post-metadata">

**Author:** ![minhajpasha](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/minhajpasha/32/1159_2.png) [@minhajpasha](https://discourse.getdbt.com/u/minhajpasha)\
**Post date:** [January 25, 2023, 2:26pm UTC](https://discourse.getdbt.com/t/how-to-configure-environment-variables-for-dbtoperator/6316/4 "2023-01-25T14:26:59Z")

</div>

Hey, I would not recommend to Use Operators serviced by gocardless as this repo is not managed upto date. Most of the latest dbt cli flags are not supported

Regards  
Minhaj

---

<div class="post-metadata">

**Author:** ![III](https://avatars.discourse-cdn.com/v4/letter/i/ecb155/32.png) [@III](https://discourse.getdbt.com/u/III)\
**Post date:** [January 26, 2023, 4:41pm UTC](https://discourse.getdbt.com/t/how-to-configure-environment-variables-for-dbtoperator/6316/5 "2023-01-26T16:41:18Z")

</div>

> [@minhajpasha](#):
>
> Hey, I would not recommend to Use Operators serviced by gocardless as this repo is not managed upto date. Most of the latest dbt cli flags are not supported

Thanks Minhaj, can you please recommend an alternative for dbt\_core?

---

<div class="post-metadata">

**Author:** ![minhajpasha](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/minhajpasha/32/1159_2.png) [@minhajpasha](https://discourse.getdbt.com/u/minhajpasha)\
**Post date:** [January 27, 2023, 8:43am UTC](https://discourse.getdbt.com/t/how-to-configure-environment-variables-for-dbtoperator/6316/6 "2023-01-27T08:43:34Z")

</div>

Hey,  
Easy option: Run the dbt commands from Bash Operator to start with.  
-If you are on airflow composer then would recommend running dbt over kubernatespodoperator  
-not yet ready for production workloads, but you may try this option too.

> **[Marc Lamberti on LinkedIn: #dataengineering #dataengineer #airflow | 113...](https://www.linkedin.com/posts/marclamberti_dataengineering-dataengineer-airflow-activity-7023650783468355585-vCPZ?utm_source=share&utm_medium=member_android)**
>
> Data Engineers... Stop WASTING your time!
> 
> There is a NEW way to integrate Dbt with Airflow 👇
> 
> Say "hello" to Cosmos 🤩
> 
> Automatically convert your Dbt… | 113 comments on LinkedIn

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/getdbt/original/1X/a7a7ca1fe379aaf90952b0e13118a817babcd14f.png) [@system](https://discourse.getdbt.com/u/system)\
**Post date:** [February 3, 2023, 8:43am UTC](https://discourse.getdbt.com/t/how-to-configure-environment-variables-for-dbtoperator/6316/7 "2023-02-03T08:43:41Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
