Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions ocne2/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
108 changes: 108 additions & 0 deletions ocne2/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
---
# 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: Launch an 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 }}"
shape: "{{ instance_shape }}"
shape_config:
ocpus: "{{ instance_ocpus }}"
memory_in_gbs: "{{ instance_memory }}"
create_vnic_details:
assign_public_ip: true
hostname_label: "{{ item.value.instance_name | default('instance-'~timestamp) }}"
subnet_id: "{{ my_subnet_id }}"
metadata:
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
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:
- "Launched a new instance:"
- "{{ result }}"
when: debug_enabled

- name: Set the compute instance id
ansible.builtin.set_fact:
instance_id: "{{ result.instance.id }}"

- name: Set the compute instance display_name
ansible.builtin.set_fact:
instance_display_name: "{{ result.instance.display_name }}"

- name: Get the vnic attachment details of instance
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
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:
instance_private_ip: "{{ result.vnic.private_ip }}"

- name: Set the instance public ip address
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:
- "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: "{{ item.value.type }}"
ansible_user: opc
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 }}"
Loading