<p>I have the following dir structure</p>
<pre><code>.
├── ConfigSpark.yaml
├── project1
│   ├── dags
│   │   └── dag_1.py
│   └── sparkjob
│       └── spark_1.py
└── sparkutils
</code></pre>
<p>I'm trying to import de <code>ConfigSpark.yaml</code> file in my <code>SparkKubernetesOperator</code> using:</p>
<pre><code>job= SparkKubernetesOperator(
            task_id = 'job',
            params=dict(
                app_name='job',
                mainApplicationFile='/opt/airflow/dags/project1/sparkjob/spark_1.py',
                driverCores=1,
                driverCoreRequest='250m',
                driverCoreLimit='500m',
                driverMemory='2G',
                executorInstances=1,
                executorCores=2,
                executorCoreRequest='1000m',
                executorCoreLimit='1000m',
                executorMemory='2G'
            ),
            application_file='/opt/airflow/dags/ConfigSpark.yaml',
            kubernetes_conn_id='conn_prd_eks',
            do_xcom_push=True
    )
</code></pre>
<p>My dag is returning the following error:</p>
<pre><code>jinja2.exceptions.TemplateNotFound: /opt/airflow/dags/ConfigSpark.yaml
</code></pre>
<p>I've noticed that if the DAG is in the same directory of ConfigSpark.yaml my tasks run perfectly, but why my task is not running when I place my dag in a subfolder?</p>
<p>I've checked my <code>values.yaml</code> file and <code>airflowHome</code> is <code>/opt/airflow</code> and <code>defaultAirflowRepository</code> is <code>apache/airflow</code>.</p>
<p>What is happening?</p>

OdiumPura
<p>Airflow searches for the template file (<code>ConfigSpark.yaml</code> in your case) from the directory in which the DAG file is stored. Therefore, it doesn't find it automatically with your code.</p>
<p>If you would store the template file in same folder your DAG file is stored in (<code>/project1/dags</code>), or a nested folder inside the <code>/project1/dags</code> folder, you can specify the path from there in your task:</p>
<pre class="lang-py prettyprint-override"><code>job = SparkKubernetesOperator(
    ...,
    application_file='/path/to/ConfigSpark.yaml',
    ...
)
</code></pre>
<p>Which would read the template file from <code>/project1/dags/path/to/ConfigSpark.yaml</code>.</p>
<p>However, if the folder your template file is stored in is not a child of the folder your DAG file is stored in, the above won't work. In that case you can specify <code>template_searchpath</code> on the DAG-level:</p>
<pre class="lang-py prettyprint-override"><code>with DAG(..., template_searchpath=&quot;/opt/airflow/dags/repo/dags&quot;) as dag:
    job = SparkKubernetesOperator(
        task_id='job',
        application_file='ConfigSpark.yaml',
        ...,
    )
</code></pre>
<p>This path (for example <code>/opt/airflow/dags</code>) is added to the Jinja searchpath and that way <code>ConfigSpark.yaml</code> will be found.</p>
