[2021-04-01 03:12:52,404] {bash_operator.py:158} INFO - Updating project ssh metadata...
[2021-04-01 03:13:09,570] {bash_operator.py:158} INFO - .....................................................................................Updated [https://www.googleapis.com/compute/beta/projects/project].
[2021-04-01 03:13:10,257] {bash_operator.py:158} INFO - ...done.
[2021-04-01 03:13:10,301] {bash_operator.py:158} INFO - Waiting for SSH key to propagate.
[2021-04-01 03:13:10,573] {bash_operator.py:158} INFO - Warning: Permanently added 'compute.6676320815635940303' (ECDSA) to the list of known hosts.
[2021-04-01 03:13:10,665] {bash_operator.py:158} INFO - [email protected]: Permission denied (publickey).
[2021-04-01 03:14:07,028] {bash_operator.py:158} INFO - ERROR: (gcloud.beta.compute.ssh) Could not SSH into the instance. It is possible that your SSH key has not propagated to the instance yet. Try running this command again. If you still cannot connect, verify that the firewall and instance are set to accept ssh traffic.
[2021-04-01 03:14:07,654] {bash_operator.py:162} INFO - Command exited with return code 1
[2021-04-01 03:14:07,697] {taskinstance.py:1152} ERROR - Bash command failed
instead使用
BashOperator()
用于SSH到您的VM实例,使用
ComputeEngineSSHHook()
并将您的参数传递到此方法。有关此方法的引用 您可以参考此github链接example_compute_ssh.py
ComputeEngineSSHook()
连接到不同的VM设置。
here是来自github链接的片段:
import os
from airflow.providers.google.cloud.hooks.compute_ssh import ComputeEngineSSHHook
from airflow.providers.ssh.operators.ssh import SSHOperator
GCP_PROJECT_ID = os.environ.get('GCP_PROJECT_ID', 'example-project')
GCE_ZONE = os.environ.get('GCE_ZONE', 'europe-west2-a')
GCE_INSTANCE = os.environ.get('GCE_INSTANCE', 'target-instance')
vm_ssh = SSHOperator(
task_id="vm_ssh",
ssh_hook=ComputeEngineSSHHook(
instance_name=GCE_INSTANCE,
zone=GCE_ZONE,
project_id=GCP_PROJECT_ID,
use_oslogin=True,
use_iap_tunnel=False,
use_internal_ip=True, // include this line if you are using internal ip
),
command="echo vm_ssh",
)
气流UI中的SSH连接提及服务器IP,用户名,密码,端口,并在以下路径中粘贴此路径。 {“ key_file”:“/home/airflow/gcs/data/gcp_key”}