Skip to content

Commit 0a21eb9

Browse files
authored
Merge pull request #68 from bgraef/main
enhancements to olvm deployment
2 parents 7de4777 + 86da2c2 commit 0a21eb9

27 files changed

+791
-148
lines changed

ol/build.yml

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,46 @@
197197
- " private ip: {{ instance_private_ip }}"
198198
when: debug_enabled
199199

200+
- name: Print SSH proxy command
201+
ansible.builtin.debug:
202+
msg: "SSH Proxy: {{ ssh_proxy_cmd | default('') }}"
203+
when: debug_enabled
204+
200205
- name: Add host to in-memory host file
201206
ansible.builtin.add_host:
202207
name: "{{ instance_display_name }}"
203208
groups: "{{ item.value.type }}"
204209
ansible_user: opc
205210
ansible_private_key_file: "{{ lookup('env', 'HOME') + '/.ssh/' + private_key }}"
206-
ansible_ssh_common_args: "-o StrictHostKeyChecking=no"
211+
ansible_ssh_common_args: "-o StrictHostKeyChecking=no {{ ssh_proxy_cmd | default('') }}"
207212
ansible_host: "{{ instance_public_ip }}"
208213
ansible_port: 22
209-
instance_ocid: "{{ instance_id }}"
214+
instance_ocid: "{{ my_instance_id }}"
215+
216+
- name: Create host ini file
217+
ansible.builtin.lineinfile:
218+
path: hosts
219+
regexp: '^\[{{ host_group }}'
220+
line: "[{{ host_group }}]"
221+
create: true
222+
mode: "0664"
223+
delegate_to: localhost
224+
loop:
225+
- engine
226+
- kvm
227+
loop_control:
228+
loop_var: host_group
229+
230+
- name: Add host to ini host file
231+
ansible.builtin.lineinfile:
232+
path: hosts
233+
regexp: '^{{ instance_name }}'
234+
line: >-
235+
{{ instance_name }}
236+
ansible_host={{ instance_ansible_host }}
237+
ansible_user={{ instance_ansible_user }}
238+
ansible_private_key_file={{ instance_ansible_private_key_file }}
239+
ansible_ssh_common_args={{ instance_ansible_ssh_common_args | quote }}
240+
insertafter: '^\[{{ item.value.type }}\]$'
241+
create: true
242+
mode: "0664"

ol/create_instance.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@
4949
ansible.builtin.set_fact:
5050
my_tenancy_id: "{{ lookup('ini', 'tenancy section={{ oci_config_section }} file={{ oci_config_file }}') }}"
5151

52+
- name: Print tenancy id
53+
ansible.builtin.debug:
54+
msg: "{{ my_tenancy_id }}"
55+
when: debug_enabled
56+
5257
- name: Get region id
5358
ansible.builtin.set_fact:
5459
my_region_id: "{{ lookup('ini', 'region section={{ oci_config_section }} file={{ oci_config_file }}') }}"

ol/default_vars.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,15 @@ virtualbox_extpack_version: "7.1.2"
5959
ol_iso_version: "9"
6060
ol_update: "4"
6161
dwnld_ol_iso: false
62+
63+
# ssh_proxy_cmd: '-o ProxyCommand="nc --proxy www.example.com:80 %h %p"'
64+
65+
# pip_proxy_env:
66+
# http_proxy: 'http://www.example.com:80
67+
# https_proxy: 'https://www.example.com:80'
68+
69+
# proxy_env:
70+
# http_proxy: 'www.example.com:80'
71+
# https_proxy: 'www.example.com:80'
72+
# ftp_proxy: 'www.example.com:80'
73+
# no_proxy: 'localhost,127.0.0.1,example.com'

ol/host_setup.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,21 @@
2020
# search_regex: OpenSSH
2121
# delay: 10
2222

23-
- name: Wait for system to become reachable
23+
- name: Wait for connection to systems to become reachable
2424
ansible.builtin.wait_for_connection:
2525
vars:
2626
python_version: "/usr/bin/python3"
2727
ansible_python_interpreter: "{{ python_version if localhost_python_interpreter is defined | default(omit) }}"
28+
when: ssh_proxy_cmd is undefined
29+
30+
- name: Wait for systems to become reachable using ssh
31+
ansible.builtin.wait_for:
32+
port: 22
33+
host: '{{ (ansible_ssh_host | default(ansible_host)) | default(inventory_hostname) }}'
34+
search_regex: OpenSSH
35+
delay: 10
36+
timeout: 300
37+
when: ssh_proxy_cmd is defined
2838

2939
# - name: Run ansible adhoc ping module
3040
# ansible.builtin.command: ansible all -i '{{ hostvars[inventory_hostname].ansible_host }},' -m ping

ol/update_all_rpms.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
when: ansible_distribution == 'OracleLinux'
2121
retries: 5
2222
delay: 10
23+
environment: "{{ proxy_env | default({}) }}"
2324

2425
- name: Check if a reboot is required
2526
ansible.builtin.command: /usr/bin/needs-restarting -r

olvm/build.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@
4848
ansible.builtin.set_fact:
4949
my_instance_id: "{{ result.instance.id }}"
5050

51+
- name: Add instance id to state file
52+
ansible.builtin.lineinfile:
53+
path: .ansible-state
54+
line: "instance{{ ansible_loop.index0 + 1 }}_ocid: {{ my_instance_id }}"
55+
mode: "0755"
56+
5157
- name: Set the compute instance display_name
5258
ansible.builtin.set_fact:
5359
instance_display_name: "{{ result.instance.display_name }}"
@@ -201,13 +207,18 @@
201207
- " private ip: {{ instance_private_ip }}"
202208
when: debug_enabled
203209

210+
- name: Print SSH proxy command
211+
ansible.builtin.debug:
212+
msg: "SSH Proxy: {{ ssh_proxy_cmd | default('') }}"
213+
when: debug_enabled
214+
204215
- name: Add host to in-memory host file
205216
ansible.builtin.add_host:
206217
name: "{{ instance_display_name }}"
207218
groups: "{{ item.value.type }}"
208219
ansible_user: opc
209220
ansible_private_key_file: "{{ lookup('env', 'HOME') + '/.ssh/' + private_key }}"
210-
ansible_ssh_common_args: "-o StrictHostKeyChecking=no"
221+
ansible_ssh_common_args: "-o StrictHostKeyChecking=no {{ ssh_proxy_cmd | default('') }}"
211222
ansible_host: "{{ instance_public_ip }}"
212223
ansible_port: 22
213224
instance_ocid: "{{ my_instance_id }}"
@@ -244,6 +255,6 @@
244255
instance_name: "{{ instance_display_name }}"
245256
instance_ansible_user: opc
246257
instance_ansible_private_key_file: "{{ lookup('env', 'HOME') + '/.ssh/' + private_key }}"
247-
instance_ansible_ssh_common_args: "-o StrictHostKeyChecking=no"
258+
instance_ansible_ssh_common_args: "-o StrictHostKeyChecking=no {{ ssh_proxy_cmd | default('') }}"
248259
instance_ansible_host: "{{ instance_public_ip }}"
249260
instance_ansible_port: 22

olvm/check_instance_available.yml

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

77
- name: Configure new instances
8-
hosts: all
8+
hosts: engine:kvm:!localhost
99
gather_facts: false
1010
vars_files:
1111
- default_vars.yml
1212
- oci_vars.yml
1313

1414
tasks:
1515

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) }}"
16+
- name: Wait for systems to become reachable using ssh
17+
ansible.builtin.wait_for:
18+
port: 22
19+
host: '{{ (ansible_ssh_host | default(ansible_host)) | default(inventory_hostname) }}'
20+
search_regex: OpenSSH
21+
delay: 10
22+
timeout: 300
2123

2224
- name: Get a set of all available facts
2325
ansible.builtin.setup:

olvm/configure_passwordless_ssh.yml

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

77
- name: Configure passwordless ssh between hosts
8-
hosts: all
8+
hosts: engine:kvm:!localhost
99
vars_files:
1010
- default_vars.yml
1111
- oci_vars.yml
@@ -33,7 +33,8 @@
3333
user: "{{ username }}"
3434
state: present
3535
key: "{{ lookup('file', 'buffer/{{ item }}-id_rsa.pub') }}"
36-
loop: "{{ groups['all'] | flatten(levels=1) }}"
36+
# loop: "{{ groups['all'] | flatten(levels=1) }}"
37+
loop: "{{ ansible_play_hosts_all | difference(['localhost']) }}"
3738
become: true
3839

3940
# - name: Copy public key to each destination for root
@@ -47,7 +48,8 @@
4748
- name: Print hostvars for groups
4849
ansible.builtin.debug:
4950
msg: "{{ hostvars[item] }}"
50-
loop: "{{ groups['all'] | flatten(levels=1) }}"
51+
# loop: "{{ groups['all'] | flatten(levels=1) }}"
52+
loop: "{{ ansible_play_hosts_all | difference(['localhost']) }}"
5153
when: debug_enabled
5254

5355
- name: Print vcn subnet_domain_name
@@ -62,7 +64,8 @@
6264
{{ hostvars[item].ansible_default_ipv4.address }},\
6365
{{ hostvars[item].ansible_hostname + '.' + my_subnet1_domain_name }} >> ~/.ssh/known_hosts
6466
with_items:
65-
- "{{ groups['all'] }}"
67+
# - "{{ groups['all'] }}"
68+
"{{ ansible_play_hosts_all | difference(['localhost']) }}"
6669
become: true
6770
become_user: "{{ username }}"
6871
register: result

olvm/configure_secondary_nic.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# See LICENSE.TXT for details.
66

77
- name: Configure secondary nic
8-
hosts: all
8+
hosts: engine,kvm
99
vars_files:
1010
- default_vars.yml
1111
- oci_vars.yml
@@ -87,8 +87,13 @@
8787
- name: Get network interface
8888
ansible.builtin.set_fact:
8989
interface: "{{ item }}"
90-
with_items: "{{ ansible_interfaces | reject('==', 'lo') }}"
91-
when: ansible_facts[item].macaddress == mac_addr
90+
with_items: "{{ ansible_interfaces | select('match', '^(ens|enp|eth)') | list }}"
91+
when: ansible_facts[item].macaddress is defined and ansible_facts[item].macaddress == mac_addr
92+
93+
- name: Check if kvm hosts added to olvm cluster
94+
ansible.builtin.stat:
95+
path: /tmp/.olvm-provisioned
96+
register: olvm_provision
9297

9398
- name: Assign static IP
9499
community.general.nmcli:
@@ -99,6 +104,7 @@
99104
gw4: 10.0.1.1
100105
state: present
101106
become: true
107+
when: not olvm_provision.stat.exists
102108

103109
- name: Add two IPv4 DNS server addresses
104110
community.general.nmcli:
@@ -109,3 +115,4 @@
109115
- 169.254.169.254
110116
state: present
111117
become: true
118+
when: not olvm_provision.stat.exists

olvm/create_block_storage.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
ansible.builtin.set_fact:
2121
volume_id: "{{ kvm_create_block.volume.id }}"
2222

23+
- name: Add storage id to state file
24+
ansible.builtin.lineinfile:
25+
path: .ansible-state
26+
line: "{{ storage_name }}_ocid: {{ volume_id }}"
27+
mode: "0755"
28+
2329
- name: Attach shared block volume for vm storage
2430
oracle.oci.oci_compute_volume_attachment:
2531
instance_id: "{{ my_instance_id }}"

0 commit comments

Comments
 (0)