Skip to content

Instantly share code, notes, and snippets.

@dariobanfi
Created June 3, 2022 13:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dariobanfi/e8d3107f7a3b9ebcb569bdc63c80fac7 to your computer and use it in GitHub Desktop.
Save dariobanfi/e8d3107f7a3b9ebcb569bdc63c80fac7 to your computer and use it in GitHub Desktop.
Multi-NIC Google Compute Engine Instances example in Ansible
- name: Create a Disk for the VML
google.cloud.gcp_compute_disk:
name: ansible-disk
size_gb: 10
zone: "{{ lookup('env', 'GCP_ZONE') }}"
project: "{{ lookup('env', 'GCP_PROJECT') }}"
auth_kind: serviceaccount
service_account_file: "{{ lookup('env', 'GCP_SERVICE_ACCOUNT_FILE') }}"
state: present
register: disk
- name: create a network
google.cloud.gcp_compute_network:
name: ansible-network-1
project: "{{ lookup('env', 'GCP_PROJECT') }}"
auth_kind: "serviceaccount"
service_account_file: "{{ lookup('env', 'GCP_SERVICE_ACCOUNT_FILE') }}"
auto_create_subnetworks: no
state: present
register: network1
- name: create a subnetwork
google.cloud.gcp_compute_subnetwork:
name: ansible-subnetwork-1
region: "{{ lookup('env', 'GCP_REGION') }}"
network: "{{ network1 }}"
ip_cidr_range: 10.0.0.0/24
project: "{{ lookup('env', 'GCP_PROJECT') }}"
auth_kind: serviceaccount
service_account_file: "{{ lookup('env', 'GCP_SERVICE_ACCOUNT_FILE') }}"
state: present
register: subnetwork1
- name: create a network
google.cloud.gcp_compute_network:
name: ansible-network-2
project: "{{ lookup('env', 'GCP_PROJECT') }}"
auth_kind: "serviceaccount"
service_account_file: "{{ lookup('env', 'GCP_SERVICE_ACCOUNT_FILE') }}"
auto_create_subnetworks: no
state: present
register: network2
- name: create a subnetwork
google.cloud.gcp_compute_subnetwork:
name: ansible-subnetwork-2
region: "{{ lookup('env', 'GCP_REGION') }}"
network: "{{ network2 }}"
ip_cidr_range: 10.0.1.0/24
project: "{{ lookup('env', 'GCP_PROJECT') }}"
auth_kind: serviceaccount
service_account_file: "{{ lookup('env', 'GCP_SERVICE_ACCOUNT_FILE') }}"
state: present
register: subnetwork2
- name: create a instance
google.cloud.gcp_compute_instance:
name: ansible-compute-engine-instance
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
network_interfaces:
- network: "{{ subnetwork1 }}"
- network: "{{ subnetwork2 }}"
zone: "{{ lookup('env', 'GCP_ZONE') }}"
project: "{{ lookup('env', 'GCP_PROJECT') }}"
auth_kind: serviceaccount
service_account_file: "{{ lookup('env', 'GCP_SERVICE_ACCOUNT_FILE') }}"
state: present
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment