Skip to content
2 changes: 1 addition & 1 deletion ol/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@

- name: Add block storage to an instance
ansible.builtin.include_tasks: "block.yml"
loop: "{{ query('sequence', 'start=1 end='+(block_count)|string) }}"
loop: "{{ query('sequence', 'start=1 end=' + (block_count) | string) }}"
loop_control:
extended: true
vars:
Expand Down
2 changes: 1 addition & 1 deletion ol/host_setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
become: true
register: result
changed_when: result.rc == 0

- name: Add user account with access to sudo
ansible.builtin.user:
name: "{{ username }}"
Expand Down
2 changes: 1 addition & 1 deletion ol/passwordless_setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
community.crypto.openssh_keypair:
path: ~/.ssh/id_rsa
size: 2048
comment: ocne ssh keypair
comment: ol ssh keypair
become: true
become_user: "{{ username }}"

Expand Down
39 changes: 39 additions & 0 deletions olam/block.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
# Copyright (c) 2024 Oracle and/or its affiliates.
# This software is made available to you under the terms of the Universal Permissive License (UPL), Version 1.0.
# The Universal Permissive License (UPL), Version 1.0 (see COPYING or https://oss.oracle.com/licenses/upl)
# See LICENSE.TXT for details.

- name: Add block volumes to the instance
when:
- add_block_storage
block:
- name: Create block volume
oracle.oci.oci_blockstorage_volume:
compartment_id: "{{ my_compartment_id }}"
availability_domain: "{{ my_availability_domain }}"
display_name: "blockvolume-{{ item.value.instance_name | default('instance-'~timestamp) }}"
size_in_gbs: "{{ block_volume_size_in_gbs }}"
register: result
vars:
timestamp: "{{ now().strftime('%Y%m%d-%H%M%S') }}"
retries: 10
delay: 30
until: result is not failed

- name: Set the block volume id
ansible.builtin.set_fact:
volume_id: "{{ result.volume.id }}"

- name: Attach the block volume
oracle.oci.oci_compute_volume_attachment:
instance_id: "{{ instance_id }}"
type: paravirtualized
volume_id: "{{ volume_id }}"
compartment_id: "{{ my_compartment_id }}"
device: "/dev/oracleoci/oraclevd{{ block_devices[ansible_loop.index0] }}"
is_read_only: false
is_shareable: false
retries: 10
delay: 30
until: result is not failed
61 changes: 40 additions & 21 deletions olam/build.yaml → olam/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,45 @@
# See LICENSE.TXT for details.

- name: Launch an instance
oci_compute_instance:
oracle.oci.oci_compute_instance:
availability_domain: "{{ my_availability_domain }}"
compartment_id: "{{ my_compartment_id }}"
name: "{{ item.value.instance_name | default('instance-'~timestamp) }}"
image_id: "{{ ol_image_id }}"
display_name: "{{ item.value.instance_name | default('instance-'~timestamp) }}"
source_details:
image_id: "{{ ol_image_id }}"
source_type: image
boot_volume_size_in_gbs: "{{ item.value.boot_volume_size_in_gbs | default(50) | int }}"
shape: "{{ instance_shape }}"
shape_config:
ocpus: "{{ instance_ocpus }}"
memory_in_gbs: "{{ instance_memory }}"
create_vnic_details:
assign_public_ip: true
display_name: "{{ item.value.instance_name | default('instance-'~timestamp) }}-vnic"
hostname_label: "{{ item.value.instance_name | default('instance-'~timestamp) }}"
subnet_id: "{{ my_subnet_id }}"
hostname_label: "{{ item.value.instance_name | default('instance-'~timestamp) }}"
metadata:
ssh_authorized_keys: "{{ lookup('file', lookup('env','HOME') + '/.ssh/' + private_key + '.pub' ) }}"
ssh_authorized_keys: "{{ lookup('file', lookup('env', 'HOME') + '/.ssh/' + private_key + '.pub') }}"
agent_config:
is_monitoring_disabled: false
is_management_disabled: false
are_all_plugins_disabled: false
plugins_config:
-
name: "OS Management Service Agent"
desired_state: DISABLED
-
name: "OS Management Service Agent"
desired_state: DISABLED
key_by: [compartment_id, availability_domain, display_name]
register: result
vars:
timestamp: "{{ now().strftime('%Y%m%d-%H%M%S') }}"
retries: 10
delay: 30
until: result is not failed

- name: Print instance details
ansible.builtin.debug:
msg:
msg:
- "Launched a new instance:"
- "{{ result }}"
when: debug_enabled
Expand All @@ -51,15 +57,21 @@
instance_display_name: "{{ result.instance.display_name }}"

- name: Get the vnic attachment details of instance
oci_compute_vnic_attachment_facts:
oracle.oci.oci_compute_vnic_attachment_facts:
compartment_id: "{{ my_compartment_id }}"
instance_id: "{{ instance_id }}"
register: result
retries: 10
delay: 30
until: result is not failed

- name: Get vnic details
oci_network_vnic_facts:
oracle.oci.oci_network_vnic_facts:
id: "{{ result.vnic_attachments[0].vnic_id }}"
register: result
retries: 10
delay: 30
until: result is not failed

- name: Set the instance private ip address
ansible.builtin.set_fact:
Expand All @@ -69,27 +81,34 @@
ansible.builtin.set_fact:
instance_public_ip: "{{ result.vnic.public_ip }}"

- name: Add block storage to an instance
ansible.builtin.include_tasks: "block.yml"
loop: "{{ query('sequence', 'start=1 end=' + (block_count) | string) }}"
loop_control:
extended: true
vars:
block_devices:
- b
- c
- d
- e
- f

- name: Print the public and private ip of the newly created instance
ansible.builtin.debug:
msg:
msg:
- "Instance name: {{ instance_display_name }}"
- " public ip: {{ instance_public_ip }}"
- " private ip: {{ instance_private_ip }}"
when: debug_enabled

- name: Add host to in-memory host file
ansible.builtin.add_host:
name: "{{ instance_display_name }}"
groups: "in_memory"
groups: "{{ item.value.type }}"
ansible_user: opc
ansible_ssh_private_key_file: "{{ lookup('env','HOME') + '/.ssh/' + private_key }}"
ansible_private_key_file: "{{ lookup('env', 'HOME') + '/.ssh/' + private_key }}"
ansible_ssh_common_args: "-o StrictHostKeyChecking=no"
ansible_host: "{{ instance_public_ip }}"
ansible_port: 22
instance_ocid: "{{ instance_id }}"

# - name: Add instance to the state file
# ansible.builtin.lineinfile:
# path: /tmp/ansible.state
# line: "id{{ groups['in_memory'].index(instance_display_name) }}: {{ instance_id }}"
# create: true
Loading