And then, if I indent the arguments in a large text block, the BashOperator complains that the bash_command is too long. So I get rid of the indents and line ending escapes and set it up like this which ends up with a bash operator that looks like this, which _almost_ works:
I don't recommend generating new SSH keys with each task execution; you are likely to run out of GCE metadata this way (see https://cloud.google.com/compute/docs/storing-retrieving-metadata).Composer mounts a few folders from GCS through which you could mount a static SSH key: https://cloud.google.com/composer/docs/concepts/cloud-storage. I'd recommend putting it under "dags" or "plugins" as it has the most reliable sync method.
[2018-09-18 17:49:12,312] {base_task_runner.py:98} INFO - Subtask: [2018-09-18 17:49:12,312] {bash_operator.py:101} INFO - @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
[2018-09-18 17:49:12,314] {base_task_runner.py:98} INFO - Subtask: [2018-09-18 17:49:12,313] {bash_operator.py:101} INFO - @ WARNING: UNPROTECTED PRIVATE KEY FILE! @
[2018-09-18 17:49:12,314] {base_task_runner.py:98} INFO - Subtask: [2018-09-18 17:49:12,314] {bash_operator.py:101} INFO - @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
[2018-09-18 17:49:12,315] {base_task_runner.py:98} INFO - Subtask: [2018-09-18 17:49:12,315] {bash_operator.py:101} INFO - Permissions 0644 for '/home/airflow/gcs/plugins/my_gcloud_key' are too open.
[2018-09-18 17:49:12,316] {base_task_runner.py:98} INFO - Subtask: [2018-09-18 17:49:12,316] {bash_operator.py:101} INFO - It is recommended that your private key files are NOT accessible by others.
[2018-09-18 17:49:12,316] {base_task_runner.py:98} INFO - Subtask: [2018-09-18 17:49:12,316] {bash_operator.py:101} INFO - This private key will be ignored.
[2018-09-18 17:49:12,317] {base_task_runner.py:98} INFO - Subtask: [2018-09-18 17:49:12,317] {bash_operator.py:101} INFO - key_load_private_type: bad permissionsI get this which isn't obvious how to fix. Should I run a "chmod" from the DAG before I try to invoke ssh? There is nothing in the bucket set up that is obvious that will let me do a chmod 400 on the keyfiles.
sshCommand = "chmod 400 /home/airflow/gcs/plugins/my_gcloud_key; \
gcloud compute ssh some_user@my_vm \
--zone=us-central1-f --ssh-key-file=/home/airflow/gcs/plugins/my_gcloud_key \
-- -p 22333"
snapshots = BashOperator(
task_id='mytask',
bash_command=sshCommand + ' "some_script.bash"',
dag=dag
)