I am creating some BashOperators within PythonOperator but it is not working. Task t1 reads conf parameter from the context have and return a value and second task t2 which is Python operator read the value using xcom, I am able to read the value but task in for loop are not create.
Is it Possible to create a BashOperator in PythonOperator?
from airflow import DAG
from airflow.operators.bash_operator import BashOperator
from airflow.operators.python_operator import PythonOperator
from datetime import datetime
def load_properties(comment_char='#', sep='=', **kwargs):
#some processing
return kwargs['dag_run'].conf.get('propname')
def createtask(**kwargs):
property_from_task1=ti.xcom_pull(key=None, task_ids='t1')
for value in range(property_from_task1):
task = BashOperator(task_id=task_name, bash_command='echo creating a commond', dag=dag)
default_args = {
'owner': 'airflow',
'depends_on_past': False,
'start_date': datetime(2017, 12, 21),
'provide_context': True,
}
dag = DAG(
'param', default_args=default_args,schedule_interval=None)
t1 = PythonOperator(task_id='t1',
python_callable=load_properties,
provide_context=True,
dag=dag)
t2 = PythonOperator(task_id='t2',
python_callable=createtask,
provide_context=True,
dag=dag)
t2.set_upstream(t1)