【发布时间】:2020-11-05 00:48:31
【问题描述】:
在执行 playbook 之前,我创建了一个服务帐户并为其授予“Compute admin”、“OS Login admin”和“服务帐户”的权限用户”。然后我在我的机器上下载了 json 密钥。服务帐户状态为“活动”。 在我的机器上,我编写了一个剧本来设置一个 gcp 虚拟机并安装 apache 并在那里复制一个虚拟网页。
- name: Create Compute Engine instances
hosts: localhost
gather_facts: no
vars:
gcp_project: ansible-xxxxxx
gcp_cred_kind: serviceaccount
gcp_cred_file: ~/ansible-key.json
zone: "us-central1-a"
region: "us-central1"
machine_type: "n1-standard-1"
image: "projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts"
tasks:
- name: Create an IP address for instance
gcp_compute_address:
name: "{{ zone }}-ip"
region: "{{ region }}"
project: "{{ gcp_project }}"
service_account_file: "{{ gcp_cred_file }}"
auth_kind: "{{ gcp_cred_kind }}"
register: gce_ip
- name: Bring up the instance in the zone.
gcp_compute_instance:
name: "{{ zone }}"
machine_type: "{{ machine_type }}"
disks:
- auto_delete: true
boot: true
initialize_params:
source_image: "{{ image }}"
network_interfaces:
- access_configs:
- name: External NAT
nat_ip: "{{ gce_ip }}"
type: ONE_TO_ONE_NAT
tags:
items:
- http-server
- https-server
zone: "{{ zone }}"
project: "{{ gcp_project }}"
service_account_file: "{{ gcp_cred_file }}"
auth_kind: "{{ gcp_cred_kind }}"
register: gce
...实例化 VM 后,我通过 ssh 连接到它...
post_tasks:
- name: Wait for SSH for instance
wait_for: delay=5 sleep=5 host={{ gce_ip.address }} port=22 state=started timeout=100
- name: Save host data for first zone
add_host: hostname={{ gce_ip.address }} groupname=gce_instances_ips
ansible-playbook 永远不会通过这一步,
调用它我使用ansible-playbook main.yaml --user sa_123456789 和
给定的错误是一个
fatal: [130.211.225.130]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: sa_104318085248975873144@130.211.225.130: Permission denied (publickey).", "unreachable": true}
或简单的超时
fatal: [localhost]: FAILED! => {"changed": false, "elapsed": 105, "msg": "Timeout when waiting for 130.211.225.130:22"}
在 GCE 的元数据中,我还将 enable-oslogin 设置为 TRUE。 VM 的创建没有任何问题,并且可以使用 GCP 控制台 (GUI) 进行访问。如果我尝试使用私下生成的密钥通过 ssh 访问,则机器似乎无法访问。 有没有人遇到过这种类型的错误?
【问题讨论】:
标签: google-cloud-platform ssh ansible