- name: Create Disk
gcp_compute_disk:
name: "{{app_name}}-disk"
size_gb: 50
source_image: "{{source_image}}"
zone: "{{ gcp_zone }}"
project: web-project
auth_kind: "{{ gcp_cred_kind }}"
state: present
register: disk
- name: Reserve IP Address
gcp_compute_address:
name: "{{app_name}}-address"
region: "{{region}}"
project: vpc-project
auth_kind: "{{ gcp_cred_kind }}"
state: present
register: address
- name: Create VM Instance
gcp_compute_instance:
name: "{{app_name}}-vm"
machine_type: "{{instance_type}}"
disks:
- auto_delete: true
boot: true
source: "{{disk}}"
network_interfaces:
- subnetwork:
selfLink: "{{subnetwork}}"
access_configs:
- name: External NAT
nat_ip: "{{ address }}"
type: ONE_TO_ONE_NAT
zone: "{{ gcp_zone }}"
project: web-project
auth_kind: "{{ gcp_cred_kind }}"
state: present
register: instanceVPC存在于"vpc-project“中,并与"web-project”共享,后者没有自己的网络。
地区:美西1区:美西1 b
当我运行代码时,它使用其他项目VPC成功地创建了VM,并为它分配了一个内部IP。
但是,它没有将外部IP分配给它。我已经确认地址是在正确的区域创建的,但它只是闲置着。
只是为了测试,我让它在项目本地网络中创建一个外部地址和一个VM,但它仍然没有将公共地址分配给它。
我是不是遗漏了什么?
发布于 2022-10-06 21:37:18
John和Ferregina是正确的--一个项目的外部IP不能分配给另一个项目中的资源。我相应地改变了剧本。
然而,这不是我痛苦的原因。这是一个与剧本有关的问题。在剧中使用"selfLink“是因为某种原因,它完全忽略了关于"access_configs”的整个部分。
我把它改变了:
network_interfaces:
- subnetwork:
selfLink: "{{subnetwork}}"
access_configs:
- name: External NAT
nat_ip: "{{ address }}"
type: ONE_TO_ONE_NAT对此:
network_interfaces:
- subnetwork: "{{subnetwork_info.resources[0]}}"
access_configs:
- name: External NAT
nat_ip: "{{ external_address }}"
type: ONE_TO_ONE_NAT而且起作用了。
https://stackoverflow.com/questions/73967212
复制相似问题