|
1 | 1 | --- |
2 | | -# Copyright (c) 2024 Oracle and/or its affiliates. |
| 2 | +# Copyright (c) 2024 2025 Oracle and/or its affiliates. |
3 | 3 | # This software is made available to you under the terms of the Universal Permissive License (UPL), Version 1.0. |
4 | 4 | # The Universal Permissive License (UPL), Version 1.0 (see COPYING or https://oss.oracle.com/licenses/upl) |
5 | 5 | # See LICENSE.TXT for details. |
6 | 6 |
|
7 | 7 | - name: Launch an instance |
8 | 8 | oracle.oci.oci_compute_instance: |
| 9 | + config_file_location: "{{ oci_config_file | default(omit) }}" |
| 10 | + config_profile_name: "{{ oci_config_section | default(omit) }}" |
9 | 11 | availability_domain: "{{ my_availability_domain }}" |
10 | 12 | compartment_id: "{{ my_compartment_id }}" |
11 | 13 | display_name: "{{ item.value.instance_name | default('instance-'~timestamp) }}" |
|
50 | 52 |
|
51 | 53 | - name: Set the compute instance id |
52 | 54 | 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" |
54 | 62 |
|
55 | 63 | - name: Set the compute instance display_name |
56 | 64 | ansible.builtin.set_fact: |
57 | | - instance_display_name: "{{ result.instance.display_name }}" |
| 65 | + my_instance_display_name: "{{ result.instance.display_name }}" |
58 | 66 |
|
59 | 67 | - name: Get the vnic attachment details of instance |
60 | 68 | 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) }}" |
61 | 71 | compartment_id: "{{ my_compartment_id }}" |
62 | | - instance_id: "{{ instance_id }}" |
| 72 | + instance_id: "{{ my_instance_id }}" |
63 | 73 | register: result |
64 | 74 | retries: 10 |
65 | 75 | delay: 30 |
66 | 76 | until: result is not failed |
67 | 77 |
|
68 | 78 | - name: Get vnic details |
69 | 79 | oracle.oci.oci_network_vnic_facts: |
| 80 | + config_file_location: "{{ oci_config_file | default(omit) }}" |
| 81 | + config_profile_name: "{{ oci_config_section | default(omit) }}" |
70 | 82 | id: "{{ result.vnic_attachments[0].vnic_id }}" |
71 | 83 | register: result |
72 | 84 | retries: 10 |
|
86 | 98 | loop: "{{ query('sequence', 'start=1 end=' + (block_count) | string) }}" |
87 | 99 | loop_control: |
88 | 100 | extended: true |
| 101 | + loop_var: blk_item |
89 | 102 | vars: |
90 | 103 | block_devices: |
91 | 104 | - b |
|
97 | 110 | - name: Print the public and private ip of the newly created instance |
98 | 111 | ansible.builtin.debug: |
99 | 112 | msg: |
100 | | - - "Instance name: {{ instance_display_name }}" |
| 113 | + - "Instance name: {{ my_instance_display_name }}" |
101 | 114 | - " public ip: {{ instance_public_ip }}" |
102 | 115 | - " private ip: {{ instance_private_ip }}" |
103 | 116 | when: debug_enabled |
104 | 117 |
|
105 | 118 | - name: Add host to in-memory host file |
106 | 119 | ansible.builtin.add_host: |
107 | | - name: "{{ instance_display_name }}" |
| 120 | + name: "{{ my_instance_display_name }}" |
108 | 121 | groups: "{{ item.value.type }}" |
109 | 122 | ansible_user: opc |
110 | 123 | ansible_private_key_file: "{{ lookup('env', 'HOME') + '/.ssh/' + private_key }}" |
111 | 124 | ansible_ssh_common_args: "-o StrictHostKeyChecking=no" |
112 | 125 | ansible_host: "{{ instance_public_ip }}" |
113 | 126 | ansible_port: 22 |
114 | | - instance_ocid: "{{ instance_id }}" |
| 127 | + instance_ocid: "{{ my_instance_id }}" |
115 | 128 |
|
116 | 129 | - name: Create host ini file |
117 | 130 | ansible.builtin.lineinfile: |
118 | 131 | path: hosts |
119 | | - regexp: '^\[{{ host_group }}' |
120 | | - line: "[{{ host_group }}]" |
| 132 | + regexp: '^\[{{ item.value.type }}' |
| 133 | + line: "[{{ item.value.type }}]" |
121 | 134 | create: true |
122 | 135 | mode: "0664" |
123 | 136 | 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 |
130 | 143 |
|
131 | 144 | - name: Add host to ini host file |
132 | 145 | ansible.builtin.lineinfile: |
|
143 | 156 | mode: "664" |
144 | 157 | delegate_to: localhost |
145 | 158 | vars: |
146 | | - instance_name: "{{ instance_display_name }}" |
| 159 | + instance_name: "{{ my_instance_display_name }}" |
147 | 160 | instance_ansible_user: opc |
148 | 161 | instance_ansible_private_key_file: "{{ lookup('env', 'HOME') + '/.ssh/' + private_key }}" |
149 | 162 | instance_ansible_ssh_common_args: "-o StrictHostKeyChecking=no" |
|
0 commit comments