Skip to content

Commit 6a7ddd0

Browse files
authored
Merge pull request #56 from bgraef/main
add olvm deployment
2 parents be8c86b + 0481b3e commit 6a7ddd0

22 files changed

+1788
-0
lines changed

olvm/build.yml

Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
---
2+
# Copyright (c) 2024 2025 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: "{{ item.value.instance_ocpus }}"
16+
memory_in_gbs: "{{ item.value.instance_memory }}"
17+
create_vnic_details:
18+
assign_public_ip: true
19+
hostname_label: "{{ item.value.instance_name | default('instance-'~timestamp) }}"
20+
display_name: "public"
21+
subnet_id: "{{ my_subnet1_id }}"
22+
metadata:
23+
ssh_authorized_keys: "{{ lookup('file', lookup('env', 'HOME') + '/.ssh/' + private_key + '.pub') }}"
24+
agent_config:
25+
is_monitoring_disabled: false
26+
is_management_disabled: false
27+
are_all_plugins_disabled: false
28+
plugins_config:
29+
-
30+
name: "OS Management Service Agent"
31+
desired_state: DISABLED
32+
key_by: [compartment_id, availability_domain, display_name]
33+
register: result
34+
vars:
35+
timestamp: "{{ now().strftime('%Y%m%d-%H%M%S') }}"
36+
retries: 10
37+
delay: 30
38+
until: result is not failed
39+
40+
- name: Print instance details
41+
ansible.builtin.debug:
42+
msg:
43+
- "Launched a new instance:"
44+
- "{{ result }}"
45+
when: debug_enabled
46+
47+
- name: Set the compute instance id
48+
ansible.builtin.set_fact:
49+
my_instance_id: "{{ result.instance.id }}"
50+
51+
- name: Set the compute instance display_name
52+
ansible.builtin.set_fact:
53+
instance_display_name: "{{ result.instance.display_name }}"
54+
55+
# - name: Get the primary vnic attachment details of instance
56+
# oracle.oci.oci_compute_vnic_attachment_facts:
57+
# compartment_id: "{{ my_compartment_id }}"
58+
# instance_id: "{{ my_instance_id }}"
59+
# register: result
60+
# retries: 10
61+
# delay: 30
62+
# until: result is not failed
63+
64+
# - name: Get primary vnic details
65+
# oracle.oci.oci_network_vnic_facts:
66+
# vnic_id: "{{ result.vnic_attachments[0].vnic_id }}"
67+
# register: result
68+
# retries: 10
69+
# delay: 30
70+
# until: result is not failed
71+
72+
- name: Set the instance primary private ip address
73+
ansible.builtin.set_fact:
74+
instance_private_ip: "{{ result.instance.primary_private_ip }}"
75+
76+
- name: Set the instance primary public ip address
77+
ansible.builtin.set_fact:
78+
instance_public_ip: "{{ result.instance.primary_public_ip }}"
79+
80+
- name: Add secondary private subnet vnic_attachment
81+
when: item.value.type == "engine"
82+
block:
83+
- name: Create subnet2 vnic_attachment
84+
oracle.oci.oci_compute_vnic_attachment:
85+
compartment_id: "{{ my_compartment_id }}"
86+
create_vnic_details:
87+
assign_public_ip: false
88+
assign_private_dns_record: true
89+
display_name: "vdsm"
90+
hostname_label: "vdsm"
91+
subnet_id: "{{ my_subnet2_id }}"
92+
display_name: "vdsm"
93+
instance_id: "{{ my_instance_id }}"
94+
key_by: [compartment_id, display_name]
95+
register: engine_subnet2
96+
retries: 10
97+
delay: 30
98+
until: engine_subnet2 is not failed
99+
100+
- name: Print vnic_attachment for subnet2
101+
ansible.builtin.debug:
102+
var: engine_subnet2
103+
when: debug_enabled
104+
105+
- name: Add secondary private subnet vnic_attachment
106+
when: item.value.type == "kvm"
107+
block:
108+
- name: Create subnet2 vnic_attachment
109+
oracle.oci.oci_compute_vnic_attachment:
110+
compartment_id: "{{ my_compartment_id }}"
111+
create_vnic_details:
112+
assign_public_ip: false
113+
assign_private_dns_record: true
114+
display_name: "vdsm{{ item.value.instance_name[-2:] }}"
115+
hostname_label: "vdsm{{ item.value.instance_name[-2:] }}"
116+
subnet_id: "{{ my_subnet2_id }}"
117+
display_name: "vdsm{{ item.value.instance_name[-2:] }}"
118+
instance_id: "{{ my_instance_id }}"
119+
key_by: [compartment_id, display_name]
120+
register: kvm_subnet2
121+
retries: 10
122+
delay: 30
123+
until: kvm_subnet2 is not failed
124+
125+
- name: Print vnic_attachment for subnet2
126+
ansible.builtin.debug:
127+
var: kvm_subnet2
128+
when: debug_enabled
129+
130+
- name: Add vlan vnic to instance
131+
when: item.value.type == "kvm"
132+
block:
133+
- name: Create vlan vnic_attachment
134+
oracle.oci.oci_compute_vnic_attachment:
135+
compartment_id: "{{ my_compartment_id }}"
136+
create_vnic_details:
137+
assign_public_ip: false
138+
display_name: "l2-vm-network"
139+
vlan_id: "{{ my_vlan_id }}"
140+
display_name: "l2-vm-network"
141+
instance_id: "{{ my_instance_id }}"
142+
register: kvm_vlan
143+
retries: 10
144+
delay: 30
145+
until: kvm_vlan is not failed
146+
147+
- name: Print vnic_attachment for vlan
148+
ansible.builtin.debug:
149+
var: kvm_vlan
150+
when: debug_enabled
151+
152+
- name: Add block volumes for vm storage domains
153+
ansible.builtin.include_tasks: create_block_storage.yml
154+
loop:
155+
- "amd-storage-domain-01"
156+
- "amd-storage-domain-02"
157+
loop_control:
158+
loop_var: storage_name
159+
when:
160+
- item.value.type == "kvm"
161+
162+
# - name: Add shared block volume to kvm nodes for vm storage
163+
# when:
164+
# - item.value.type == "kvm"
165+
# - add_vm_block_storage
166+
# block:
167+
# - name: Create block volume for vm storage
168+
# oracle.oci.oci_blockstorage_volume:
169+
# compartment_id: "{{ my_compartment_id }}"
170+
# availability_domain: "{{ my_availability_domain }}"
171+
# display_name: "amd-storage-domain-01"
172+
# size_in_gbs: "{{ blk_volume_size_in_gbs }}"
173+
# key_by: [compartment_id, display_name]
174+
# register: kvm_create_block
175+
# retries: 10
176+
# delay: 30
177+
# until: kvm_create_block is not failed
178+
179+
# - name: Set the block storage block volume id
180+
# ansible.builtin.set_fact:
181+
# volume_id: "{{ kvm_create_block.volume.id }}"
182+
183+
# - name: Attach shared block volume for vm storage
184+
# oracle.oci.oci_compute_volume_attachment:
185+
# instance_id: "{{ my_instance_id }}"
186+
# type: paravirtualized
187+
# volume_id: "{{ volume_id }}"
188+
# compartment_id: "{{ my_compartment_id }}"
189+
# is_read_only: false
190+
# is_shareable: true
191+
# register: kvm_add_block
192+
# retries: 10
193+
# delay: 30
194+
# until: kvm_add_block is not failed
195+
196+
- name: Print the public and private ip of the newly created instance
197+
ansible.builtin.debug:
198+
msg:
199+
- "Instance name: {{ instance_display_name }}"
200+
- " public ip: {{ instance_public_ip }}"
201+
- " private ip: {{ instance_private_ip }}"
202+
when: debug_enabled
203+
204+
- name: Add host to in-memory host file
205+
ansible.builtin.add_host:
206+
name: "{{ instance_display_name }}"
207+
groups: "{{ item.value.type }}"
208+
ansible_user: opc
209+
ansible_private_key_file: "{{ lookup('env', 'HOME') + '/.ssh/' + private_key }}"
210+
ansible_ssh_common_args: "-o StrictHostKeyChecking=no"
211+
ansible_host: "{{ instance_public_ip }}"
212+
ansible_port: 22
213+
instance_ocid: "{{ my_instance_id }}"
214+
215+
- name: Create host ini file
216+
ansible.builtin.lineinfile:
217+
path: hosts
218+
regexp: '^\[{{ host_group }}'
219+
line: "[{{ host_group }}]"
220+
create: true
221+
mode: "0664"
222+
delegate_to: localhost
223+
loop:
224+
- engine
225+
- kvm
226+
loop_control:
227+
loop_var: host_group
228+
229+
- name: Add host to ini host file
230+
ansible.builtin.lineinfile:
231+
path: hosts
232+
regexp: '^{{ instance_name }}'
233+
line: >-
234+
{{ instance_name }}
235+
ansible_host={{ instance_ansible_host }}
236+
ansible_user={{ instance_ansible_user }}
237+
ansible_private_key_file={{ instance_ansible_private_key_file }}
238+
ansible_ssh_common_args={{ instance_ansible_ssh_common_args | quote }}
239+
insertafter: '^\[{{ item.value.type }}\]$'
240+
create: true
241+
mode: "664"
242+
delegate_to: localhost
243+
vars:
244+
instance_name: "{{ instance_display_name }}"
245+
instance_ansible_user: opc
246+
instance_ansible_private_key_file: "{{ lookup('env', 'HOME') + '/.ssh/' + private_key }}"
247+
instance_ansible_ssh_common_args: "-o StrictHostKeyChecking=no"
248+
instance_ansible_host: "{{ instance_public_ip }}"
249+
instance_ansible_port: 22

olvm/check_instance_available.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
# Copyright (c) 2024 2025 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: Configure new instances
8+
hosts: all
9+
gather_facts: false
10+
vars_files:
11+
- default_vars.yml
12+
- oci_vars.yml
13+
14+
tasks:
15+
16+
- name: Wait for systems to become reachable
17+
ansible.builtin.wait_for_connection:
18+
vars:
19+
python_version: "/usr/bin/python3"
20+
ansible_python_interpreter: "{{ python_version if localhost_python_interpreter is defined | default(omit) }}"
21+
22+
- name: Get a set of all available facts
23+
ansible.builtin.setup:
24+
25+
- name: Print in-memory inventory # noqa: run-once[task]
26+
ansible.builtin.debug:
27+
msg: "{{ groups['all'] }}"
28+
delegate_to: localhost
29+
run_once: true
30+
when: debug_enabled
31+
32+
- name: Print all variables/facts known for a host # noqa: run-once[task]
33+
ansible.builtin.debug:
34+
msg: "{{ hostvars[item] }}"
35+
loop: "{{ groups['all'] | flatten(levels=1) }}"
36+
delegate_to: localhost
37+
run_once: true
38+
when: debug_enabled

olvm/configure_passwordless_ssh.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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: Configure passwordless ssh between hosts
8+
hosts: all
9+
vars_files:
10+
- default_vars.yml
11+
- oci_vars.yml
12+
13+
tasks:
14+
15+
- name: Generate ssh keypair for user
16+
community.crypto.openssh_keypair:
17+
path: ~/.ssh/id_rsa
18+
size: 2048
19+
comment: ol ssh keypair
20+
become: true
21+
become_user: "{{ username }}"
22+
23+
- name: Fetch public key file
24+
ansible.builtin.fetch:
25+
src: "~/.ssh/id_rsa.pub"
26+
dest: "buffer/{{ inventory_hostname }}-id_rsa.pub"
27+
flat: true
28+
become: true
29+
become_user: "{{ username }}"
30+
31+
- name: Copy public key to each destination
32+
ansible.posix.authorized_key:
33+
user: "{{ username }}"
34+
state: present
35+
key: "{{ lookup('file', 'buffer/{{ item }}-id_rsa.pub') }}"
36+
loop: "{{ groups['all'] | flatten(levels=1) }}"
37+
become: true
38+
39+
# - name: Copy public key to each destination for root
40+
# ansible.posix.authorized_key:
41+
# user: "root"
42+
# state: present
43+
# key: "{{ lookup('file', 'buffer/{{ item }}-id_rsa.pub') }}"
44+
# loop: "{{ groups['all'] | flatten(levels=1) }}"
45+
# become: true
46+
47+
- name: Print hostvars for groups
48+
ansible.builtin.debug:
49+
msg: "{{ hostvars[item] }}"
50+
loop: "{{ groups['all'] | flatten(levels=1) }}"
51+
when: debug_enabled
52+
53+
- name: Print vcn subnet_domain_name
54+
ansible.builtin.debug:
55+
var: my_subnet1_domain_name
56+
when: debug_enabled
57+
58+
- name: Accept new ssh fingerprints
59+
ansible.builtin.shell: |
60+
ssh-keyscan -t ecdsa-sha2-nistp256 \
61+
{{ hostvars[item].ansible_hostname }},\
62+
{{ hostvars[item].ansible_default_ipv4.address }},\
63+
{{ hostvars[item].ansible_hostname + '.' + my_subnet1_domain_name }} >> ~/.ssh/known_hosts
64+
with_items:
65+
- "{{ groups['all'] }}"
66+
become: true
67+
become_user: "{{ username }}"
68+
register: result
69+
changed_when: result.rc == 0
70+
71+
# - name: Accept new ssh fingerprints for root
72+
# ansible.builtin.shell: |
73+
# ssh-keyscan -t ecdsa-sha2-nistp256 \
74+
# {{ hostvars[item].ansible_hostname }},\
75+
# {{ hostvars[item].ansible_default_ipv4.address }},\
76+
# {{ hostvars[item].ansible_hostname + '.' + my_subnet1_domain_name }} >> ~/.ssh/known_hosts
77+
# with_items:
78+
# - "{{ groups['all'] }}"
79+
# become: true
80+
# become_user: "root"
81+
# register: result
82+
# changed_when: result.rc == 0

0 commit comments

Comments
 (0)