-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.yaml
116 lines (109 loc) · 4.22 KB
/
setup.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
---
# Copyright (c) 2018, Oracle and/or its affiliates.
# This software is made available to you under the terms of the GPL 3.0 license or the Apache 2.0 license.
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Apache License v2.0
# See LICENSE.TXT for details.
# - name: Check pre-requisites
# fail:
# msg: "Environment variable {{item}} not set. Please declare an environment variable with an appropriate value for the sample to work."
# when: item not in ansible_env
# with_items:
# - "SAMPLE_COMPARTMENT_OCID"
# - "SAMPLE_IMAGE_OCID"
# - "SAMPLE_AD_NAME"
- name: Create a temporary directory to house a temporary SSH keypair we will later use to connect to instance
tempfile:
state: directory
suffix: cert
register: result
- set_fact:
temp_certificates_path: "{{ result.path }}"
- name: Generate a Private Key
openssl_privatekey:
path: "{{ temp_certificates_path }}/private_key.pem"
type: RSA
size: 2048
- set_fact:
my_test_public_key: "{{ temp_certificates_path }}/public_key.pem"
- name: Generate a Public Key
openssl_publickey:
path: "{{ my_test_public_key }}"
privatekey_path: "{{ temp_certificates_path }}/private_key.pem"
format: OpenSSH
- name: Create a VCN
oci_vcn:
compartment_id: "{{ instance_compartment }}"
display_name: "{{ vcn_name }}"
cidr_block: "{{ vcn_cidr_block }}"
dns_label: "{{ vcn_dns_label }}"
# shell: "oci network vcn create -c {{ instance_compartment }} --cidr-block {{ vcn_cidr_block }} --display-name {{ vcn_name }} --dns-label {{ vcn_dns_label }}"
register: result
- set_fact:
vcn_id: "{{ result.vcn.id }}"
- name : Create a new Internet Gateway
oci_internet_gateway:
compartment_id: "{{ instance_compartment }}"
vcn_id: "{{ vcn_id }}"
name: "{{ ig_name }}"
enabled: 'yes'
state: 'present'
register: result
- set_fact:
ig_id: "{{ result.internet_gateway.id }}"
- name: Create route table to connect internet gateway to the VCN
oci_route_table:
compartment_id: "{{ instance_compartment }}"
vcn_id: "{{ vcn_id }}"
name: "{{ route_table_name }}"
route_rules: "{{ route_table_rules }}"
state: 'present'
register: result
- set_fact:
rt_id: "{{ result.route_table.id }}"
# Create a security list for allowing access to public instance
# Use a jinja2 template of the ingress and egress security rules to generate
# a templated version of the final rules.
- name: create ingress rules yaml body
template: src=./templates/ingress_security_rules.yaml.j2 dest=/tmp/instance_ingress_security_rules.yaml
- name: create egress yaml body
template: src=./templates/egress_security_rules.yaml.j2 dest=/tmp/instance_egress_security_rules.yaml
# Load the variables defined in the generated files
- name: load the variables defined in the ingress rules yaml body
include_vars:
file: /tmp/instance_ingress_security_rules.yaml
name: loaded_ingress
- name: print loaded_ingress
debug:
msg: "loaded ingress is {{loaded_ingress}}"
- name: load the variables defined in the egress rules yaml body
include_vars:
file: /tmp/instance_egress_security_rules.yaml
name: loaded_egress
- name: print loaded_egress
debug:
msg: "loaded egress is {{loaded_egress}}"
- name: Create a security list for allowing access to public instance
oci_security_list:
name: "{{ securitylist_name }}"
compartment_id: "{{ instance_compartment }}"
vcn_id: '{{ vcn_id }}'
ingress_security_rules: "{{ loaded_ingress.instance_ingress_security_rules }}"
egress_security_rules: "{{ loaded_egress.instance_egress_security_rules }}"
register: result
- set_fact:
instance_security_list_ocid: "{{ result.security_list.id }}"
- name: Create a subnet to host the public instance. Link security_list and route_table.
oci_subnet:
availability_domain: "{{ instance_ad }}"
cidr_block: "{{ subnet_cidr }}"
compartment_id: "{{ instance_compartment }}"
display_name: "{{ subnet_name }}"
prohibit_public_ip_on_vnic: false
route_table_id: "{{ rt_id }}"
security_list_ids: [ "{{ instance_security_list_ocid }}" ]
vcn_id: '{{ vcn_id }}'
dns_label: "{{ subnet_dns_label }}"
register: result
- set_fact:
instance_subnet_id: "{{ result.subnet.id }}"