|
5 | 5 | # See LICENSE.TXT for details. |
6 | 6 |
|
7 | 7 | - name: Launch an instance |
8 | | - oci_compute_instance: |
| 8 | + oracle.oci.oci_compute_instance: |
9 | 9 | availability_domain: "{{ my_availability_domain }}" |
10 | 10 | compartment_id: "{{ my_compartment_id }}" |
11 | | - name: "{{ item.value.instance_name | default('instance-'~timestamp) }}" |
12 | | - image_id: "{{ ol_image_id }}" |
| 11 | + display_name: "{{ item.value.instance_name | default('instance-'~timestamp) }}" |
| 12 | + source_details: |
| 13 | + image_id: "{{ ol_image_id }}" |
| 14 | + source_type: image |
| 15 | + boot_volume_size_in_gbs: "{{ item.value.boot_volume_size_in_gbs | default(50) | int }}" |
13 | 16 | shape: "{{ instance_shape }}" |
14 | 17 | shape_config: |
15 | 18 | ocpus: "{{ instance_ocpus }}" |
16 | 19 | memory_in_gbs: "{{ instance_memory }}" |
17 | 20 | create_vnic_details: |
18 | 21 | assign_public_ip: true |
| 22 | + display_name: "{{ item.value.instance_name | default('instance-'~timestamp) }}-vnic" |
19 | 23 | hostname_label: "{{ item.value.instance_name | default('instance-'~timestamp) }}" |
20 | 24 | subnet_id: "{{ my_subnet_id }}" |
| 25 | + hostname_label: "{{ item.value.instance_name | default('instance-'~timestamp) }}" |
21 | 26 | metadata: |
22 | | - ssh_authorized_keys: "{{ lookup('file', lookup('env','HOME') + '/.ssh/' + private_key + '.pub' ) }}" |
| 27 | + ssh_authorized_keys: "{{ lookup('file', lookup('env', 'HOME') + '/.ssh/' + private_key + '.pub') }}" |
23 | 28 | agent_config: |
24 | 29 | is_monitoring_disabled: false |
25 | 30 | is_management_disabled: false |
26 | 31 | are_all_plugins_disabled: false |
27 | 32 | plugins_config: |
28 | | - - |
29 | | - name: "OS Management Service Agent" |
30 | | - desired_state: DISABLED |
| 33 | + - |
| 34 | + name: "OS Management Service Agent" |
| 35 | + desired_state: DISABLED |
| 36 | + key_by: [compartment_id, availability_domain, display_name] |
31 | 37 | register: result |
32 | 38 | vars: |
33 | 39 | timestamp: "{{ now().strftime('%Y%m%d-%H%M%S') }}" |
34 | 40 | retries: 10 |
35 | 41 | delay: 30 |
36 | 42 | until: result is not failed |
37 | | - |
| 43 | + |
38 | 44 | - name: Print instance details |
39 | 45 | ansible.builtin.debug: |
40 | | - msg: |
| 46 | + msg: |
41 | 47 | - "Launched a new instance:" |
42 | 48 | - "{{ result }}" |
43 | 49 | when: debug_enabled |
|
51 | 57 | instance_display_name: "{{ result.instance.display_name }}" |
52 | 58 |
|
53 | 59 | - name: Get the vnic attachment details of instance |
54 | | - oci_compute_vnic_attachment_facts: |
| 60 | + oracle.oci.oci_compute_vnic_attachment_facts: |
55 | 61 | compartment_id: "{{ my_compartment_id }}" |
56 | 62 | instance_id: "{{ instance_id }}" |
57 | 63 | register: result |
| 64 | + retries: 10 |
| 65 | + delay: 30 |
| 66 | + until: result is not failed |
58 | 67 |
|
59 | 68 | - name: Get vnic details |
60 | | - oci_network_vnic_facts: |
| 69 | + oracle.oci.oci_network_vnic_facts: |
61 | 70 | id: "{{ result.vnic_attachments[0].vnic_id }}" |
62 | 71 | register: result |
| 72 | + retries: 10 |
| 73 | + delay: 30 |
| 74 | + until: result is not failed |
63 | 75 |
|
64 | 76 | - name: Set the instance private ip address |
65 | 77 | ansible.builtin.set_fact: |
|
69 | 81 | ansible.builtin.set_fact: |
70 | 82 | instance_public_ip: "{{ result.vnic.public_ip }}" |
71 | 83 |
|
| 84 | +- name: Add block storage to an instance |
| 85 | + ansible.builtin.include_tasks: "block.yml" |
| 86 | + loop: "{{ query('sequence', 'start=1 end=' + (block_count) | string) }}" |
| 87 | + loop_control: |
| 88 | + extended: true |
| 89 | + vars: |
| 90 | + block_devices: |
| 91 | + - b |
| 92 | + - c |
| 93 | + - d |
| 94 | + - e |
| 95 | + - f |
| 96 | + |
72 | 97 | - name: Print the public and private ip of the newly created instance |
73 | 98 | ansible.builtin.debug: |
74 | | - msg: |
| 99 | + msg: |
75 | 100 | - "Instance name: {{ instance_display_name }}" |
76 | 101 | - " public ip: {{ instance_public_ip }}" |
77 | 102 | - " private ip: {{ instance_private_ip }}" |
78 | 103 | when: debug_enabled |
79 | | - |
| 104 | + |
80 | 105 | - name: Add host to in-memory host file |
81 | 106 | ansible.builtin.add_host: |
82 | 107 | name: "{{ instance_display_name }}" |
83 | | - groups: "in_memory" |
| 108 | + groups: "{{ item.value.type }}" |
84 | 109 | ansible_user: opc |
85 | | - ansible_ssh_private_key_file: "{{ lookup('env','HOME') + '/.ssh/' + private_key }}" |
| 110 | + ansible_private_key_file: "{{ lookup('env', 'HOME') + '/.ssh/' + private_key }}" |
86 | 111 | ansible_ssh_common_args: "-o StrictHostKeyChecking=no" |
87 | 112 | ansible_host: "{{ instance_public_ip }}" |
88 | 113 | ansible_port: 22 |
89 | 114 | instance_ocid: "{{ instance_id }}" |
90 | | - |
91 | | -# - name: Add instance to the state file |
92 | | -# ansible.builtin.lineinfile: |
93 | | -# path: /tmp/ansible.state |
94 | | -# line: "id{{ groups['in_memory'].index(instance_display_name) }}: {{ instance_id }}" |
95 | | -# create: true |
|
0 commit comments