oci.yml: launch only where the capacity report shows room

A launch without A1 capacity just sits queued (ACCEPTED, 0%), and the old
retry stacked more queued launches. Now every AD is checked first; with no
capacity anywhere the run stops with a clear message and launches nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
PhilandClaude Opus 5.5 committed 2026-11-27 19:16:15 -07:00
1 parent 0d7645f1f4
commit b5436dd68c
1 file changed
+38 -6
+38 -6
View File
@@ -18,7 +18,7 @@
oci_boot_volume_gbs: 50 oci_boot_volume_gbs: 50
oci_data_volume_gbs: 50 oci_data_volume_gbs: 50
oci_storage_budget_gbs: 100 # of the tenancy's 200 GB; the rest stays free oci_storage_budget_gbs: 100 # of the tenancy's 200 GB; the rest stays free
oci_ad_index: 1 # retry on another AD with -e oci_ad_index=2 oci_ad_index: 1 # preferred AD; others are tried if it has no capacity
oci_vcn_cidr: 10.40.0.0/24 oci_vcn_cidr: 10.40.0.0/24
# The modules need an OCI config file; it's written to a private temp # The modules need an OCI config file; it's written to a private temp
# dir from vault_oci and removed at the end. # dir from vault_oci and removed at the end.
@@ -168,13 +168,47 @@
register: oci_images register: oci_images
when: oci_live | length == 0 when: oci_live | length == 0
# Free A1 capacity is often exhausted. Check every AD first and only
# launch where there is room: a launch without capacity just sits
# queued (ACCEPTED, 0%) and repeated tries pile up queued requests.
- name: A1 capacity per availability domain
oracle.oci.oci_compute_capacity_report:
<<: *oci_auth
compartment_id: "{{ vault_oci.tenancy }}"
availability_domain: "{{ item }}"
shape_availabilities:
- instance_shape: "{{ oci_shape }}"
instance_shape_config:
ocpus: "{{ oci_ocpus }}"
memory_in_gbs: "{{ oci_memory_gbs }}"
loop: "{{ ([oci_ad] + (oci_ads.availability_domains | map(attribute='name') | sort | list)) | unique }}"
register: oci_capacity
when: oci_live | length == 0
- name: Pick an availability domain with capacity
ansible.builtin.set_fact:
oci_launch_ad: "{{ oci_capacity.results
| selectattr('compute_capacity_report', 'defined')
| selectattr('compute_capacity_report.shape_availabilities.0.availability_status', 'equalto', 'AVAILABLE')
| map(attribute='item') | first | default('') }}"
when: oci_live | length == 0
- name: Stop if no availability domain has capacity
ansible.builtin.fail:
msg: >-
No {{ oci_shape }} {{ oci_ocpus }} OCPU / {{ oci_memory_gbs }} GB capacity in any
availability domain of {{ vault_oci.region }} right now
({{ oci_capacity.results | map(attribute='compute_capacity_report.shape_availabilities.0.availability_status', default='?') | join(', ') }}).
Nothing was launched; run oci.yml again later.
when: oci_live | length == 0 and oci_launch_ad == ''
# Created once; later runs never touch it (so a newer image can't # Created once; later runs never touch it (so a newer image can't
# trigger anything). "Out of host capacity" is retried. # trigger anything).
- name: Instance - name: Instance
oracle.oci.oci_compute_instance: oracle.oci.oci_compute_instance:
<<: *oci_auth <<: *oci_auth
compartment_id: "{{ oci_cid }}" compartment_id: "{{ oci_cid }}"
availability_domain: "{{ oci_ad }}" availability_domain: "{{ oci_launch_ad }}"
display_name: "{{ oci_instance_name }}" display_name: "{{ oci_instance_name }}"
shape: "{{ oci_shape }}" shape: "{{ oci_shape }}"
shape_config: shape_config:
@@ -191,10 +225,8 @@
metadata: metadata:
user_data: "{{ lookup('template', 'cogitator-04-cloud-init.yml.j2') | b64encode }}" user_data: "{{ lookup('template', 'cogitator-04-cloud-init.yml.j2') | b64encode }}"
wait: true wait: true
wait_timeout: 900
register: oci_new register: oci_new
retries: 30
delay: 60
until: oci_new is succeeded or 'capacity' not in (oci_new.msg | default('') | lower)
when: oci_live | length == 0 when: oci_live | length == 0
no_log: true # user_data contains the Tailscale auth key no_log: true # user_data contains the Tailscale auth key