Skip to content

Commit b47e6fe

Browse files
authored
Merge pull request #31 from bgraef/main
add oci device option to block devices and init for ocne2
2 parents 9a5faa4 + 95f2be3 commit b47e6fe

14 files changed

+936
-0
lines changed

ocne2/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

ocne2/build.yml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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: Launch an instance
8+
oracle.oci.oci_compute_instance:
9+
availability_domain: "{{ my_availability_domain }}"
10+
compartment_id: "{{ my_compartment_id }}"
11+
name: "{{ item.value.instance_name | default('instance-'~timestamp) }}"
12+
image_id: "{{ ol_image_id }}"
13+
shape: "{{ instance_shape }}"
14+
shape_config:
15+
ocpus: "{{ instance_ocpus }}"
16+
memory_in_gbs: "{{ instance_memory }}"
17+
create_vnic_details:
18+
assign_public_ip: true
19+
hostname_label: "{{ item.value.instance_name | default('instance-'~timestamp) }}"
20+
subnet_id: "{{ my_subnet_id }}"
21+
metadata:
22+
ssh_authorized_keys: "{{ lookup('file', lookup('env', 'HOME') + '/.ssh/' + private_key + '.pub') }}"
23+
agent_config:
24+
is_monitoring_disabled: false
25+
is_management_disabled: false
26+
are_all_plugins_disabled: false
27+
plugins_config:
28+
-
29+
name: "OS Management Service Agent"
30+
desired_state: DISABLED
31+
register: result
32+
vars:
33+
timestamp: "{{ now().strftime('%Y%m%d-%H%M%S') }}"
34+
retries: 10
35+
delay: 30
36+
until: result is not failed
37+
38+
- name: Print instance details
39+
ansible.builtin.debug:
40+
msg:
41+
- "Launched a new instance:"
42+
- "{{ result }}"
43+
when: debug_enabled
44+
45+
- name: Set the compute instance id
46+
ansible.builtin.set_fact:
47+
instance_id: "{{ result.instance.id }}"
48+
49+
- name: Set the compute instance display_name
50+
ansible.builtin.set_fact:
51+
instance_display_name: "{{ result.instance.display_name }}"
52+
53+
- name: Get the vnic attachment details of instance
54+
oracle.oci.oci_compute_vnic_attachment_facts:
55+
compartment_id: "{{ my_compartment_id }}"
56+
instance_id: "{{ instance_id }}"
57+
register: result
58+
retries: 10
59+
delay: 30
60+
until: result is not failed
61+
62+
- name: Get vnic details
63+
oracle.oci.oci_network_vnic_facts:
64+
id: "{{ result.vnic_attachments[0].vnic_id }}"
65+
register: result
66+
retries: 10
67+
delay: 30
68+
until: result is not failed
69+
70+
- name: Set the instance private ip address
71+
ansible.builtin.set_fact:
72+
instance_private_ip: "{{ result.vnic.private_ip }}"
73+
74+
- name: Set the instance public ip address
75+
ansible.builtin.set_fact:
76+
instance_public_ip: "{{ result.vnic.public_ip }}"
77+
78+
- name: Add block storage to an instance
79+
ansible.builtin.include_tasks: "block.yml"
80+
loop: "{{ query('sequence', 'start=1 end='+(block_count)|string) }}"
81+
loop_control:
82+
extended: true
83+
vars:
84+
block_devices:
85+
- b
86+
- c
87+
- d
88+
- e
89+
- f
90+
91+
- name: Print the public and private ip of the newly created instance
92+
ansible.builtin.debug:
93+
msg:
94+
- "Instance name: {{ instance_display_name }}"
95+
- " public ip: {{ instance_public_ip }}"
96+
- " private ip: {{ instance_private_ip }}"
97+
when: debug_enabled
98+
99+
- name: Add host to in-memory host file
100+
ansible.builtin.add_host:
101+
name: "{{ instance_display_name }}"
102+
groups: "{{ item.value.type }}"
103+
ansible_user: opc
104+
ansible_private_key_file: "{{ lookup('env', 'HOME') + '/.ssh/' + private_key }}"
105+
ansible_ssh_common_args: "-o StrictHostKeyChecking=no"
106+
ansible_host: "{{ instance_public_ip }}"
107+
ansible_port: 22
108+
instance_ocid: "{{ instance_id }}"

0 commit comments

Comments
 (0)