为 Ansible google.cloud.compute_instance 指定子网 [英] Specifying a subnetwork for Ansible google.cloud.compute_instance

查看:27
本文介绍了为 Ansible google.cloud.compute_instance 指定子网的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了所有我能想到的组合来指定将 google 计算实例部署到网络 (networkY) 中的特定子网 (subnetX).

I have tried every combination I can conceive of to specify to deploy a google compute instance into a particular subnet (subnetX) in network (networkY).

- name: create a instance
  google.cloud.gcp_compute_instance:
    name: test_object
    machine_type: n1-standard-1
    disks:
    - auto_delete: 'true'
      boot: 'true'
      source: "{{ disk }}"
    - auto_delete: 'true'
      interface: NVME
      type: SCRATCH
      initialize_params:
        disk_type: local-ssd
    labels:
      environment: production
    network_interfaces:   # <<< does not work. API request is made without a network_interface
    - network:
       selfLink: "https://blah/blah/blah/networkY"
      subnetwork:
       selfLink: "https://blah/blah/blah/subnetworkX"
    zone: us-central1-a
    project: test_project
    auth_kind: serviceaccount
    service_account_file: "/tmp/auth.pem"
    state: present

推荐答案

更准确地说,这是解决此问题的方法.

To be more precise this is the workaround for this problem.

---
- name: create a network
  gcp_compute_network:
    name: ansible-network
    auto_create_subnetworks: yes
    project: "{{ lookup('env','GCP_PROJECT') }}"
    state: present
  register: network

- name: Get Network URL
  set_fact:
    network_url: "{{ network | json_query(jmesquery) }}"
  vars:
    jmesquery: "{selfLink: selfLink}"

- name: create a firewall
  gcp_compute_firewall:
    name: ansible-firewall
    network: "{{ network_url }}"
    allowed:
    - ip_protocol: tcp
      ports: ['80','22']
    target_tags:
      - apache-http-server
    source_ranges: ['0.0.0.0/0']
    project: "{{ lookup('env','GCP_PROJECT') }}"
    state: present
  register: firewall

这篇关于为 Ansible google.cloud.compute_instance 指定子网的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆