Google cloud platform 使用ansible和gcp创建外部和内部IP

Google cloud platform 使用ansible和gcp创建外部和内部IP,google-cloud-platform,ansible,Google Cloud Platform,Ansible,我正在使用Ansible 2.9.1使用GCP创建一些计算实例。我想为每个实例创建一个外部IP,我已经使用以下代码实现了这一点: - name: create an instance gcp_compute_instance: name: "{{ compute_inst }}" machine_type: "{{ machine }}" disks: - auto_delete: 'true' boot: 'true'

我正在使用Ansible 2.9.1使用GCP创建一些计算实例。我想为每个实例创建一个外部IP,我已经使用以下代码实现了这一点:

  - name: create an instance
    gcp_compute_instance:
      name: "{{ compute_inst }}"
      machine_type: "{{ machine }}"
      disks:
      - auto_delete: 'true'
        boot: 'true'
        source: "{{ disk }}"
      network_interfaces:
        - access_configs:
          - name: External NAT
            nat_ip: "{{ address }}"
            type: ONE_TO_ONE_NAT
      zone: "{{ zone }}"
      project: "{{ gcp_project }}"
      auth_kind: serviceaccount
      service_account_file: "{{ gcp_cred_file }}"
      state: present
    register: instance
  - name: create an instance
    gcp_compute_instance:
      name: "{{ compute_inst }}"
      machine_type: "{{ machine }}"
      disks:
      - auto_delete: 'true'
        boot: 'true'
        source: "{{ disk }}"
      network_interfaces:
        - access_configs:
          - name: External NAT
            nat_ip: "{{ address }}"
            type: ONE_TO_ONE_NAT
        - network_ip: "{{ internal_ip }}" 
      zone: "{{ zone }}"
      project: "{{ gcp_project }}"
      auth_kind: serviceaccount
      service_account_file: "{{ gcp_cred_file }}"
      state: present
    register: instance
其中地址是一个外部
gcp\u compute\u地址
。但是,我还想设置一个静态的内部IP。根据ansible
gcp\u compute\u实例
,您应该能够在网络接口列表中设置网络ip

要分配给此网络接口实例的IPv4内部网络地址。如果用户未指定,系统将分配未使用的内部IP

我已使用以下代码尝试此操作:

  - name: create an instance
    gcp_compute_instance:
      name: "{{ compute_inst }}"
      machine_type: "{{ machine }}"
      disks:
      - auto_delete: 'true'
        boot: 'true'
        source: "{{ disk }}"
      network_interfaces:
        - access_configs:
          - name: External NAT
            nat_ip: "{{ address }}"
            type: ONE_TO_ONE_NAT
      zone: "{{ zone }}"
      project: "{{ gcp_project }}"
      auth_kind: serviceaccount
      service_account_file: "{{ gcp_cred_file }}"
      state: present
    register: instance
  - name: create an instance
    gcp_compute_instance:
      name: "{{ compute_inst }}"
      machine_type: "{{ machine }}"
      disks:
      - auto_delete: 'true'
        boot: 'true'
        source: "{{ disk }}"
      network_interfaces:
        - access_configs:
          - name: External NAT
            nat_ip: "{{ address }}"
            type: ONE_TO_ONE_NAT
        - network_ip: "{{ internal_ip }}" 
      zone: "{{ zone }}"
      project: "{{ gcp_project }}"
      auth_kind: serviceaccount
      service_account_file: "{{ gcp_cred_file }}"
      state: present
    register: instance
其中
internal_ip
是包含内部ip地址的字符串。运行playbook时,出现以下错误:

Networks must be distinct for NICs attached to a VM.
因此,我再次阅读了文档,找到了网络接口的以下内容:

此接口的一系列配置。这指定如何配置此接口以与其他网络服务交互,例如连接到internet。每个实例只支持一个网络接口

我可以使用GCP控制台创建一个实例,在那里我可以获得外部IP和指定内部IP。有没有人知道我在ansible中做错了什么,或者有什么建议可以尝试