-
Notifications
You must be signed in to change notification settings - Fork 2
/
create_gcp_vm.yml
73 lines (66 loc) · 2.01 KB
/
create_gcp_vm.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
---
- name: Create virtual machine instance in GCP
hosts: localhost
gather_facts: false
tasks:
- name: Create fixed disk for OS image
google.cloud.gcp_compute_disk:
name: "{{ prefix }}-disk"
size_gb: "{{ disk_size }}"
source_image: "{{ source_image }}"
zone: "{{ zone }}"
state: present
register: disk
- name: Create VPC Network
google.cloud.gcp_compute_network:
name: "{{ prefix }}-network"
auto_create_subnetworks: false
state: present
register: network
- name: Create Subnet
google.cloud.gcp_compute_subnetwork:
name: "{{ prefix }}-subnet"
region: "{{ region }}"
ip_cidr_range: "{{ subnet_cidr }}"
network: "{{ network }}"
state: present
register: subnet
- name: Reserve a static IP Address
google.cloud.gcp_compute_address:
name: "{{ prefix }}-ip"
region: "{{ region }}"
state: present
register: address
- name: Create Virtual Machine
google.cloud.gcp_compute_instance:
state: present
name: "{{ prefix }}-vm"
machine_type: "{{ machine_type }}"
zone: "{{ zone }}"
disks:
- auto_delete: true
boot: true
source: "{{ disk }}"
network_interfaces:
- network: "{{ network }}"
subnetwork: "{{ subnet }}"
access_configs:
- name: External NAT
type: ONE_TO_ONE_NAT
nat_ip: "{{ address }}"
- name: Configuring firewall to allow SSH access
google.cloud.gcp_compute_firewall:
name: "{{ prefix }}-ssh-rule"
direction: "ingress"
disabled: "false"
allowed:
- ip_protocol: tcp
ports:
- '22'
network: "{{ network }}"
priority: "1000"
source_ranges: "0.0.0.0/0"
state: present
- name: Display VM Public IP
debug:
msg: "Your public IP address is: {{ address.address }}"