Skip to content

Commit dac4bee

Browse files
authored
Merge pull request #39 from bgraef/main
add initial olae updates
2 parents 30ef397 + 11d3a79 commit dac4bee

17 files changed

+745
-35
lines changed

ol/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080

8181
- name: Add block storage to an instance
8282
ansible.builtin.include_tasks: "block.yml"
83-
loop: "{{ query('sequence', 'start=1 end='+(block_count)|string) }}"
83+
loop: "{{ query('sequence', 'start=1 end=' + (block_count) | string) }}"
8484
loop_control:
8585
extended: true
8686
vars:

ol/host_setup.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
become: true
4444
register: result
4545
changed_when: result.rc == 0
46-
46+
4747
- name: Add user account with access to sudo
4848
ansible.builtin.user:
4949
name: "{{ username }}"

ol/passwordless_setup.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
community.crypto.openssh_keypair:
99
path: ~/.ssh/id_rsa
1010
size: 2048
11-
comment: ocne ssh keypair
11+
comment: ol ssh keypair
1212
become: true
1313
become_user: "{{ username }}"
1414

olam/block.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
# Copyright (c) 2024 Oracle and/or its affiliates.
3+
# This software is made available to you under the terms of the Universal Permissive License (UPL), Version 1.0.
4+
# The Universal Permissive License (UPL), Version 1.0 (see COPYING or https://oss.oracle.com/licenses/upl)
5+
# See LICENSE.TXT for details.
6+
7+
- name: Add block volumes to the instance
8+
when:
9+
- add_block_storage
10+
block:
11+
- name: Create block volume
12+
oracle.oci.oci_blockstorage_volume:
13+
compartment_id: "{{ my_compartment_id }}"
14+
availability_domain: "{{ my_availability_domain }}"
15+
display_name: "blockvolume-{{ item.value.instance_name | default('instance-'~timestamp) }}"
16+
size_in_gbs: "{{ block_volume_size_in_gbs }}"
17+
register: result
18+
vars:
19+
timestamp: "{{ now().strftime('%Y%m%d-%H%M%S') }}"
20+
retries: 10
21+
delay: 30
22+
until: result is not failed
23+
24+
- name: Set the block volume id
25+
ansible.builtin.set_fact:
26+
volume_id: "{{ result.volume.id }}"
27+
28+
- name: Attach the block volume
29+
oracle.oci.oci_compute_volume_attachment:
30+
instance_id: "{{ instance_id }}"
31+
type: paravirtualized
32+
volume_id: "{{ volume_id }}"
33+
compartment_id: "{{ my_compartment_id }}"
34+
device: "/dev/oracleoci/oraclevd{{ block_devices[ansible_loop.index0] }}"
35+
is_read_only: false
36+
is_shareable: false
37+
retries: 10
38+
delay: 30
39+
until: result is not failed

olam/build.yaml renamed to olam/build.yml

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,45 @@
55
# See LICENSE.TXT for details.
66

77
- name: Launch an instance
8-
oci_compute_instance:
8+
oracle.oci.oci_compute_instance:
99
availability_domain: "{{ my_availability_domain }}"
1010
compartment_id: "{{ my_compartment_id }}"
11-
name: "{{ item.value.instance_name | default('instance-'~timestamp) }}"
12-
image_id: "{{ ol_image_id }}"
11+
display_name: "{{ item.value.instance_name | default('instance-'~timestamp) }}"
12+
source_details:
13+
image_id: "{{ ol_image_id }}"
14+
source_type: image
15+
boot_volume_size_in_gbs: "{{ item.value.boot_volume_size_in_gbs | default(50) | int }}"
1316
shape: "{{ instance_shape }}"
1417
shape_config:
1518
ocpus: "{{ instance_ocpus }}"
1619
memory_in_gbs: "{{ instance_memory }}"
1720
create_vnic_details:
1821
assign_public_ip: true
22+
display_name: "{{ item.value.instance_name | default('instance-'~timestamp) }}-vnic"
1923
hostname_label: "{{ item.value.instance_name | default('instance-'~timestamp) }}"
2024
subnet_id: "{{ my_subnet_id }}"
25+
hostname_label: "{{ item.value.instance_name | default('instance-'~timestamp) }}"
2126
metadata:
22-
ssh_authorized_keys: "{{ lookup('file', lookup('env','HOME') + '/.ssh/' + private_key + '.pub' ) }}"
27+
ssh_authorized_keys: "{{ lookup('file', lookup('env', 'HOME') + '/.ssh/' + private_key + '.pub') }}"
2328
agent_config:
2429
is_monitoring_disabled: false
2530
is_management_disabled: false
2631
are_all_plugins_disabled: false
2732
plugins_config:
28-
-
29-
name: "OS Management Service Agent"
30-
desired_state: DISABLED
33+
-
34+
name: "OS Management Service Agent"
35+
desired_state: DISABLED
36+
key_by: [compartment_id, availability_domain, display_name]
3137
register: result
3238
vars:
3339
timestamp: "{{ now().strftime('%Y%m%d-%H%M%S') }}"
3440
retries: 10
3541
delay: 30
3642
until: result is not failed
37-
43+
3844
- name: Print instance details
3945
ansible.builtin.debug:
40-
msg:
46+
msg:
4147
- "Launched a new instance:"
4248
- "{{ result }}"
4349
when: debug_enabled
@@ -51,15 +57,21 @@
5157
instance_display_name: "{{ result.instance.display_name }}"
5258

5359
- name: Get the vnic attachment details of instance
54-
oci_compute_vnic_attachment_facts:
60+
oracle.oci.oci_compute_vnic_attachment_facts:
5561
compartment_id: "{{ my_compartment_id }}"
5662
instance_id: "{{ instance_id }}"
5763
register: result
64+
retries: 10
65+
delay: 30
66+
until: result is not failed
5867

5968
- name: Get vnic details
60-
oci_network_vnic_facts:
69+
oracle.oci.oci_network_vnic_facts:
6170
id: "{{ result.vnic_attachments[0].vnic_id }}"
6271
register: result
72+
retries: 10
73+
delay: 30
74+
until: result is not failed
6375

6476
- name: Set the instance private ip address
6577
ansible.builtin.set_fact:
@@ -69,27 +81,34 @@
6981
ansible.builtin.set_fact:
7082
instance_public_ip: "{{ result.vnic.public_ip }}"
7183

84+
- name: Add block storage to an instance
85+
ansible.builtin.include_tasks: "block.yml"
86+
loop: "{{ query('sequence', 'start=1 end=' + (block_count) | string) }}"
87+
loop_control:
88+
extended: true
89+
vars:
90+
block_devices:
91+
- b
92+
- c
93+
- d
94+
- e
95+
- f
96+
7297
- name: Print the public and private ip of the newly created instance
7398
ansible.builtin.debug:
74-
msg:
99+
msg:
75100
- "Instance name: {{ instance_display_name }}"
76101
- " public ip: {{ instance_public_ip }}"
77102
- " private ip: {{ instance_private_ip }}"
78103
when: debug_enabled
79-
104+
80105
- name: Add host to in-memory host file
81106
ansible.builtin.add_host:
82107
name: "{{ instance_display_name }}"
83-
groups: "in_memory"
108+
groups: "{{ item.value.type }}"
84109
ansible_user: opc
85-
ansible_ssh_private_key_file: "{{ lookup('env','HOME') + '/.ssh/' + private_key }}"
110+
ansible_private_key_file: "{{ lookup('env', 'HOME') + '/.ssh/' + private_key }}"
86111
ansible_ssh_common_args: "-o StrictHostKeyChecking=no"
87112
ansible_host: "{{ instance_public_ip }}"
88113
ansible_port: 22
89114
instance_ocid: "{{ instance_id }}"
90-
91-
# - name: Add instance to the state file
92-
# ansible.builtin.lineinfile:
93-
# path: /tmp/ansible.state
94-
# line: "id{{ groups['in_memory'].index(instance_display_name) }}: {{ instance_id }}"
95-
# create: true

0 commit comments

Comments
 (0)