This repository has been archived by the owner on Jan 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
provision.yaml
134 lines (112 loc) · 3.98 KB
/
provision.yaml
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
---
- name: Launch a compute instance and connect to it using SSH
hosts: localhost
collections:
- oracle.oci
vars:
# common networking definitions
quad_zero_route: "0.0.0.0/0"
TCP_protocol: "6"
SSH_port: "22"
HTTP_port: "80"
HTTPS_port: "443"
vcn_name: "rovervcn"
vcn_cidr_block: "10.0.0.0/16"
vcn_dns_label: "alwaysfreevcn"
ig_name: "roverig"
route_table_name: "roverroute"
# route all internet access to our Internet Gateway
route_table_rules:
- cidr_block: "{{ quad_zero_route }}"
network_entity_id: "{{ ig_id }}"
subnet_cidr: "10.0.0.48/28"
subnet_name: "roversubnet"
subnet_dns_label: "rovsubnet"
securitylist_name: "roversecuritylist"
# always free shape
instance_shape: "VM.Standard.E2.1.Micro"
instance_hostname: "caprover"
instance_compartment: "{{ lookup('env', 'COMPARTMENT_OCID') }}"
# provide an "OL" image
# find OL image ocids per region here: https://docs.cloud.oracle.com/iaas/images/image/501c6e22-4dc6-4e99-b045-cae47aae343f/
# make sure the image you choose is compatible with Free Tier shape - VM.Standard.E2.1.Micro
instance_image: "{{ lookup('env', 'IMAGE_OCID') }}"
tasks:
# Cleanup if you are running this a second time.
- name: remove instance.yaml
file:
path: ./instance.yaml
state: absent
- import_tasks: setup.yaml
- name: Launch an instance
oci_compute_instance:
# Disable monitoring, we have limited ressources.
agent_config:
is_monitoring_disabled: yes
availability_domain: "{{ instance_ad }}"
compartment_id: "{{ instance_compartment }}"
name: "caprover"
source_details:
source_type: image
image_id: "{{ instance_image }}"
shape: "{{ instance_shape }}"
create_vnic_details:
assign_public_ip: True
hostname_label: "{{ instance_hostname }}"
subnet_id: "{{ instance_subnet_id }}"
metadata:
ssh_authorized_keys: "{{ lookup('file', lookup('env', 'PUBLIC_KEY')) }}"
register: result
- name: Print instance details
debug:
msg: "Launched a new instance {{ result }}"
- set_fact:
instance_id: "{{result.instance.id }}"
- name: Create a volume
oci_blockstorage_volume:
availability_domain: "{{ instance_ad }}"
compartment_id: "{{ instance_compartment }}"
name: rover_volume
size_in_gbs: 50
register: result
- name: Print volume details
debug:
msg: "Created a new volume {{ result }}"
- set_fact:
volume_id: "{{result.volume.id }}"
- name: Attach volume to new instance
oci_compute_volume_attachment:
instance_id: "{{ instance_id }}"
type: paravirtualized
volume_id: "{{ volume_id }}"
compartment_id: "{{ instance_compartment }}"
register: result
- name: Print volume attachment details
debug:
msg: "Attached volume to instance {{ result }}"
- set_fact:
volume_attachment_id: "{{result.volume_attachment.id }}"
- name: Get the VNIC attachment details of instance
oci_compute_vnic_attachment_facts:
compartment_id: "{{ instance_compartment }}"
instance_id: "{{ instance_id }}"
register: result
- name: Get details of the VNIC
oci_network_vnic_facts:
id: "{{ result.vnic_attachments[0].vnic_id }}"
register: result
- set_fact:
instance_public_ip: "{{result.vnic.public_ip}}"
- name: Print the public ip of the newly launched instance
debug:
msg: "Public IP of launched instance {{ instance_public_ip }}"
- name: Wait (upto 5 minutes) for port 22 to become open
wait_for:
port: 22
host: '{{ instance_public_ip }}'
state: started
delay: 10
vars:
ansible_connection: local
- name: write facts for teardown
template: src=./templates/instance.j2 dest=./instance.yaml