2

I have this code for airflow to execute python script inside docker :

a02_retrieve_2 = SSHExecuteOperator(
    task_id='a02_retrieve_2',
    ssh_hook=sshHook,
    dag=dag,
    bash_command= 'docker exec myDocker -i bash -c "  /opt/conda/bin/python aretrieve_2.py   --myarg  45  --myarg 35   "  '
)

Unfortunately, it does not work.

But, the version with no argument works.

a02_retrieve_2 = SSHExecuteOperator(
    task_id='a02_retrieve_2',
    ssh_hook=sshHook,
    dag=dag,
    bash_command= 'docker exec myDocker -i bash -c "  /opt/conda/bin/python aretrieve_2.py  "  '
)

Error is :

Python script starts to run but Airflow is unable to catch up the python script parameters...

How to make the version with python script arguments works ?

Is this related to jinja template ? BashOperator doen't run bash file apache airflow

5
  • 1
    How does not work look like? Any logs? Commented Apr 26, 2018 at 8:21
  • 1
    You already asked this question and probably didn't get an answer because you haven't provided enough information. What does it say in your logs. Commented Apr 26, 2018 at 9:04
  • airflow does not read the python arguments Commented Apr 26, 2018 at 14:40
  • Does everything work fine if you execute bash -c " /opt/conda/bin/python aretrieve_2.py --myarg 45 --myarg 35 " directly on the machine? Commented May 2, 2018 at 7:28
  • yes, of course. this is related to jinja template in airflow Commented May 2, 2018 at 13:57

1 Answer 1

0

I found the answer by looking at the source code of bashoperator: This uses popen

            self.log.info("Running command: %s", bash_command)
            sp = Popen(
                ['bash', fname],
                stdout=PIPE, stderr=STDOUT,
                cwd=tmp_dir, env=self.env,
                preexec_fn=pre_exec)

https://airflow.incubator.apache.org/_modules/bash_operator.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.