-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample.yaml
133 lines (114 loc) · 4.51 KB
/
sample.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
---
# 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: Launch a compute instance and connect to it using SSH
hosts: localhost
vars:
# common networking definitions
quad_zero_route: "0.0.0.0/0"
TCP_protocol: "6"
SSH_port: "22"
RDP_port: "3389"
vcn_name: "mytestvcn"
vcn_cidr_block: "10.0.0.0/16"
vcn_dns_label: "mytestvcn"
ig_name: "myinternetgatewayformytestvcn"
route_table_name: "myroutetable"
# 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: "mytestsubnet"
subnet_dns_label: "mytestsubnet"
securitylist_name: "mysecuritylist"
instance_shape: "VM.Standard2.1"
instance_hostname: "mytestinstance"
#########################################
# Tenancy specific configuration
# *Note* - Override the following variables based on your tenancy
# or set a valid value for the corresponding environment variable
#########################################
instance_ad: "APRD:US-ASHBURN-AD-2"
instance_compartment: "ocid1.compartment.oc1..aaaaaaaauzjrwrpfptnkpb46ifs6gv7rwsywqpkth7tz54n7ek27upc7iwha"
# provide an "OEL" image
# instance_image: "ocid1.image.oc1.iad.aaaaaaaaz43cwpkndgjk35uqqb7hpp6a52boci6rsf7ctkyzviqaosg6m3aq"
instance_image: "ocid1.image.oc1.iad.aaaaaaaanhy6ll23jvme3mnzijksog5ilng3gzurwhhlkzflvqzwwg7swyua"
# instance_image: "ocid1.image.oc1.iad.aaaaaaaa6kbmads5tuf4ztjdrozwpknscrisu4uzcgu2fcq77armuhf4dfiq"
tasks:
- import_tasks: setup.yaml
- name: Launch an instance
oci_instance:
availability_domain: "{{ instance_ad }}"
compartment_id: "{{ instance_compartment }}"
name: "my_test_instance"
image_id: "{{ instance_image }}"
shape: "{{ instance_shape }}"
vnic:
assign_public_ip: True
hostname_label: "{{ instance_hostname }}"
subnet_id: "{{ instance_subnet_id }}"
metadata:
ssh_authorized_keys: "{{ lookup('file', my_test_public_key ) }}"
register: result
- name: Print instance details
debug:
msg: "Launched a new instance {{ result }}"
- set_fact:
instance_id: "{{result.instance.id }}"
- name: Get the VNIC attachment details of instance
oci_vnic_attachment_facts:
compartment_id: "{{ instance_compartment }}"
instance_id: "{{ instance_id }}"
register: result
- name: Get details of the VNIC
oci_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: Attempt a ssh connection to the newly launced instance
# # Use "opc" user as this is an OEL image
# # Disable SSH's strict host key checking just for this one command invocation
# command: ssh -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" -i {{ temp_certificates_path }}/private_key.pem opc@{{ instance_public_ip }} uname -a
# retries: 3
# delay: 5
# register: result
# until: result.rc == 0
# - name: Print SSH response from launched instance
# debug:
# msg: "SSH response from instance -> {{ result.stdout_lines }}"
- name: Create a zone
oci_zone:
compartment_id: "{{ instance_compartment }}"
name: nrdproperties.com
zone_type: PRIMARY
register: result
- set_fact:
zone_id: "{{ result.zone.id }}"
- name: Patch a zone's record
oci_zone_records:
name: nrdproperties.com
patch_items: [{
domain: "honeywellsmartmeters.nrdproperties.com",
is_protected: false,
rdata: "{{instance_public_ip}}",
rtype: "A",
ttl: 30,
operation: "ADD"
}]
# - import_tasks: teardown.yaml