Skip to content

Commit 887e0e3

Browse files
authored
Merge pull request #79 from bgraef/main
merge fixes for olam on ol9
2 parents 10f0a51 + 9de9bc5 commit 887e0e3

21 files changed

+765
-355
lines changed

olam/block.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
block:
1111
- name: Create block volume
1212
oracle.oci.oci_blockstorage_volume:
13+
config_file_location: "{{ oci_config_file | default(omit) }}"
14+
config_profile_name: "{{ oci_config_section | default(omit) }}"
1315
compartment_id: "{{ my_compartment_id }}"
1416
availability_domain: "{{ my_availability_domain }}"
1517
display_name: "blockvolume-{{ item.value.instance_name | default('instance-'~timestamp) }}"
@@ -27,7 +29,9 @@
2729

2830
- name: Attach the block volume
2931
oracle.oci.oci_compute_volume_attachment:
30-
instance_id: "{{ instance_id }}"
32+
config_file_location: "{{ oci_config_file | default(omit) }}"
33+
config_profile_name: "{{ oci_config_section | default(omit) }}"
34+
instance_id: "{{ my_instance_id }}"
3135
type: paravirtualized
3236
volume_id: "{{ volume_id }}"
3337
compartment_id: "{{ my_compartment_id }}"

olam/build.yml

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
---
2-
# Copyright (c) 2024 Oracle and/or its affiliates.
2+
# Copyright (c) 2024 2025 Oracle and/or its affiliates.
33
# This software is made available to you under the terms of the Universal Permissive License (UPL), Version 1.0.
44
# The Universal Permissive License (UPL), Version 1.0 (see COPYING or https://oss.oracle.com/licenses/upl)
55
# See LICENSE.TXT for details.
66

77
- name: Launch an instance
88
oracle.oci.oci_compute_instance:
9+
config_file_location: "{{ oci_config_file | default(omit) }}"
10+
config_profile_name: "{{ oci_config_section | default(omit) }}"
911
availability_domain: "{{ my_availability_domain }}"
1012
compartment_id: "{{ my_compartment_id }}"
1113
display_name: "{{ item.value.instance_name | default('instance-'~timestamp) }}"
@@ -50,23 +52,33 @@
5052

5153
- name: Set the compute instance id
5254
ansible.builtin.set_fact:
53-
instance_id: "{{ result.instance.id }}"
55+
my_instance_id: "{{ result.instance.id }}"
56+
57+
- name: Add instance id to state file
58+
ansible.builtin.lineinfile:
59+
path: .ansible-state
60+
line: "instance{{ ansible_loop.index0 + 1 }}_ocid: {{ my_instance_id }}"
61+
mode: "0755"
5462

5563
- name: Set the compute instance display_name
5664
ansible.builtin.set_fact:
57-
instance_display_name: "{{ result.instance.display_name }}"
65+
my_instance_display_name: "{{ result.instance.display_name }}"
5866

5967
- name: Get the vnic attachment details of instance
6068
oracle.oci.oci_compute_vnic_attachment_facts:
69+
config_file_location: "{{ oci_config_file | default(omit) }}"
70+
config_profile_name: "{{ oci_config_section | default(omit) }}"
6171
compartment_id: "{{ my_compartment_id }}"
62-
instance_id: "{{ instance_id }}"
72+
instance_id: "{{ my_instance_id }}"
6373
register: result
6474
retries: 10
6575
delay: 30
6676
until: result is not failed
6777

6878
- name: Get vnic details
6979
oracle.oci.oci_network_vnic_facts:
80+
config_file_location: "{{ oci_config_file | default(omit) }}"
81+
config_profile_name: "{{ oci_config_section | default(omit) }}"
7082
id: "{{ result.vnic_attachments[0].vnic_id }}"
7183
register: result
7284
retries: 10
@@ -86,6 +98,7 @@
8698
loop: "{{ query('sequence', 'start=1 end=' + (block_count) | string) }}"
8799
loop_control:
88100
extended: true
101+
loop_var: blk_item
89102
vars:
90103
block_devices:
91104
- b
@@ -97,36 +110,36 @@
97110
- name: Print the public and private ip of the newly created instance
98111
ansible.builtin.debug:
99112
msg:
100-
- "Instance name: {{ instance_display_name }}"
113+
- "Instance name: {{ my_instance_display_name }}"
101114
- " public ip: {{ instance_public_ip }}"
102115
- " private ip: {{ instance_private_ip }}"
103116
when: debug_enabled
104117

105118
- name: Add host to in-memory host file
106119
ansible.builtin.add_host:
107-
name: "{{ instance_display_name }}"
120+
name: "{{ my_instance_display_name }}"
108121
groups: "{{ item.value.type }}"
109122
ansible_user: opc
110123
ansible_private_key_file: "{{ lookup('env', 'HOME') + '/.ssh/' + private_key }}"
111124
ansible_ssh_common_args: "-o StrictHostKeyChecking=no"
112125
ansible_host: "{{ instance_public_ip }}"
113126
ansible_port: 22
114-
instance_ocid: "{{ instance_id }}"
127+
instance_ocid: "{{ my_instance_id }}"
115128

116129
- name: Create host ini file
117130
ansible.builtin.lineinfile:
118131
path: hosts
119-
regexp: '^\[{{ host_group }}'
120-
line: "[{{ host_group }}]"
132+
regexp: '^\[{{ item.value.type }}'
133+
line: "[{{ item.value.type }}]"
121134
create: true
122135
mode: "0664"
123136
delegate_to: localhost
124-
loop:
125-
- control
126-
- execution
127-
- db
128-
loop_control:
129-
loop_var: host_group
137+
# loop:
138+
# - control
139+
# - execution
140+
# - db
141+
# loop_control:
142+
# loop_var: host_group
130143

131144
- name: Add host to ini host file
132145
ansible.builtin.lineinfile:
@@ -143,7 +156,7 @@
143156
mode: "664"
144157
delegate_to: localhost
145158
vars:
146-
instance_name: "{{ instance_display_name }}"
159+
instance_name: "{{ my_instance_display_name }}"
147160
instance_ansible_user: opc
148161
instance_ansible_private_key_file: "{{ lookup('env', 'HOME') + '/.ssh/' + private_key }}"
149162
instance_ansible_ssh_common_args: "-o StrictHostKeyChecking=no"

olam/check_instance_available.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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:!localhost
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 and usable
17+
ansible.builtin.wait_for_connection:
18+
19+
# - name: Wait for systems to become reachable using ssh
20+
# ansible.builtin.wait_for:
21+
# port: 22
22+
# host: '{{ (ansible_ssh_host | default(ansible_host)) | default(inventory_hostname) }}'
23+
# search_regex: OpenSSH
24+
# delay: 10
25+
# timeout: 300
26+
27+
- name: Get a set of all available facts
28+
ansible.builtin.setup:
29+
30+
- name: Print in-memory inventory # noqa: run-once[task]
31+
ansible.builtin.debug:
32+
msg: "{{ groups['all'] }}"
33+
delegate_to: localhost
34+
run_once: true
35+
when: debug_enabled
36+
37+
- name: Print all variables/facts known for a host # noqa: run-once[task]
38+
ansible.builtin.debug:
39+
msg: "{{ hostvars[item] }}"
40+
loop: "{{ groups['all'] | flatten(levels=1) }}"
41+
delegate_to: localhost
42+
run_once: true
43+
when: debug_enabled

olam/configure_passwordless_ssh.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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:!localhost:!remote
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+
loop: "{{ ansible_play_hosts_all | difference(['localhost']) }}"
38+
become: true
39+
40+
# - name: Copy public key to each destination for root
41+
# ansible.posix.authorized_key:
42+
# user: "root"
43+
# state: present
44+
# key: "{{ lookup('file', 'buffer/{{ item }}-id_rsa.pub') }}"
45+
# loop: "{{ groups['all'] | flatten(levels=1) }}"
46+
# become: true
47+
48+
- name: Print hostvars for groups
49+
ansible.builtin.debug:
50+
msg: "{{ hostvars[item] }}"
51+
# loop: "{{ groups['all'] | flatten(levels=1) }}"
52+
loop: "{{ ansible_play_hosts_all | difference(['localhost']) }}"
53+
when: debug_enabled
54+
55+
- name: Print vcn subnet_domain_name
56+
ansible.builtin.debug:
57+
var: my_subnet1_domain_name
58+
when: debug_enabled
59+
60+
- name: Accept new ssh fingerprints
61+
ansible.builtin.shell: |
62+
ssh-keyscan -t ecdsa-sha2-nistp256 \
63+
{{ hostvars[item].ansible_hostname }},\
64+
{{ hostvars[item].ansible_default_ipv4.address }},\
65+
{{ hostvars[item].ansible_hostname + '.' + my_subnet_domain_name }} >> ~/.ssh/known_hosts
66+
with_items:
67+
# - "{{ groups['all'] }}"
68+
"{{ ansible_play_hosts_all | difference(['localhost']) }}"
69+
become: true
70+
become_user: "{{ username }}"
71+
register: result
72+
changed_when: result.rc == 0
73+
74+
# - name: Accept new ssh fingerprints for root
75+
# ansible.builtin.shell: |
76+
# ssh-keyscan -t ecdsa-sha2-nistp256 \
77+
# {{ hostvars[item].ansible_hostname }},\
78+
# {{ hostvars[item].ansible_default_ipv4.address }},\
79+
# {{ hostvars[item].ansible_hostname + '.' + my_subnet1_domain_name }} >> ~/.ssh/known_hosts
80+
# with_items:
81+
# - "{{ groups['all'] }}"
82+
# become: true
83+
# become_user: "root"
84+
# register: result
85+
# changed_when: result.rc == 0

olam/convert_ansible_inventory.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ echo ""
2727

2828
echo "[control:vars]"
2929
echo "node_type=control"
30-
echo "peers=local_execution_group"
30+
# echo "peers=local_execution_group"
3131
echo ""
3232

3333
echo "[execution]"
@@ -40,6 +40,7 @@ echo ""
4040

4141
echo "[local_execution_group:vars]"
4242
echo "node_type=execution"
43+
echo "peers=control"
4344
echo ""
4445

4546
echo "[hop]"

0 commit comments

Comments
 (0)