-
Notifications
You must be signed in to change notification settings - Fork 5
/
create-gcp-instance.yml
136 lines (126 loc) · 3.98 KB
/
create-gcp-instance.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
---
- name: Create GCP resources and then create a GCP instance
hosts: localhost
connection: local
gather_facts: false
tasks:
- name: Create a disk mapped from a RHEL-9 image for rhel1
google.cloud.gcp_compute_disk:
name: rhel1d
size_gb: 50
source_image: "projects/rhel-cloud/global/images/rhel-9-v20221102"
zone: "{{ gcp_zone }}"
project: "{{ gcp_project }}"
auth_kind: serviceaccount
state: present
register: diskrhel1
- name: Create a disk mapped from a RHEL-9 image for rhel2
google.cloud.gcp_compute_disk:
name: rhel2d
size_gb: 50
source_image: "projects/rhel-cloud/global/images/rhel-9-v20221102"
zone: "{{ gcp_zone }}"
project: "{{ gcp_project }}"
auth_kind: serviceaccount
state: present
register: diskrhel2
- name: Create a Google Virtual Private Cloud (VPC) network
google.cloud.gcp_compute_network:
name: network-instance
auto_create_subnetworks: 'false'
project: "{{ gcp_project }}"
auth_kind: serviceaccount
state: present
register: network
- name: Create a subnetwork
google.cloud.gcp_compute_subnetwork:
name: instancenet
region: "{{ gcp_region }}"
network: "{{ network }}"
ip_cidr_range: 172.16.0.0/16
project: "{{ gcp_project }}"
auth_kind: serviceaccount
state: present
register: vpcsubnet
- name: Create a firewall rule to allow SSH
google.cloud.gcp_compute_firewall:
name: allowssh
allowed:
- ip_protocol: tcp
ports:
- '22'
- '80'
- '443'
project: "{{ gcp_project }}"
network: "{{ network }}"
auth_kind: serviceaccount
state: present
register: sshallowed
- name: Create an IPv4 public IP address for rhel1
google.cloud.gcp_compute_address:
name: rhel1ip
region: "{{ gcp_region }}"
project: "{{ gcp_project }}"
auth_kind: serviceaccount
state: present
register: rhel1ip
- name: Create an IPv4 public IP address for rhel2
google.cloud.gcp_compute_address:
name: rhel2ip
region: "{{ gcp_region }}"
project: "{{ gcp_project }}"
auth_kind: serviceaccount
state: present
register: rhel2ip
- name: Create the rhel1 VM instances
google.cloud.gcp_compute_instance:
name: rhel1
machine_type: n2-standard-2
disks:
- auto_delete: 'true'
boot: 'true'
source: "{{ diskrhel1 }}"
- auto_delete: 'true'
interface: NVME
type: SCRATCH
initialize_params:
disk_type: local-ssd
labels:
environment: production
network_interfaces:
- network: "{{ network }}"
access_configs:
- name: External NAT
nat_ip: "{{ rhel1ip }}"
type: ONE_TO_ONE_NAT
subnetwork: "{{ vpcsubnet }}"
zone: "{{ gcp_zone }}"
project: "{{ gcp_project }}"
auth_kind: serviceaccount
state: present
- name: Create the rhel2 VM instances
google.cloud.gcp_compute_instance:
name: rhel2
machine_type: n2-standard-2
disks:
- auto_delete: 'true'
boot: 'true'
source: "{{ diskrhel2 }}"
- auto_delete: 'true'
interface: NVME
type: SCRATCH
initialize_params:
disk_type: local-ssd
labels:
environment: production
network_interfaces:
- network: "{{ network }}"
access_configs:
- name: External NAT
nat_ip: "{{ rhel2ip }}"
type: ONE_TO_ONE_NAT
subnetwork: "{{ vpcsubnet }}"
zone: "{{ gcp_zone }}"
project: "{{ gcp_project }}"
auth_kind: serviceaccount
state: present