Skip to content

Commit d8f5b7b

Browse files
committed
Add wait step for EC2 Spot instance creation
Introduces a new task to wait for EC2 Spot instances to be created before renaming them. The previous retry logic for renaming now checks for overall task success instead of IP address availability.
1 parent e2a96be commit d8f5b7b

File tree

1 file changed

+20
-3
lines changed
  • automation/roles/cloud_resources/tasks

1 file changed

+20
-3
lines changed

automation/roles/cloud_resources/tasks/aws.yml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,25 @@
351351
register: ec2_spot_request_result
352352
when: item.instances[0] | default('') | length < 1
353353

354+
- name: "AWS: Wait for EC2 Spot instance to be created"
355+
amazon.aws.ec2_instance:
356+
access_key: "{{ lookup('ansible.builtin.env', 'AWS_ACCESS_KEY_ID') }}"
357+
secret_key: "{{ lookup('ansible.builtin.env', 'AWS_SECRET_ACCESS_KEY') }}"
358+
region: "{{ server_location }}"
359+
filters:
360+
spot-instance-request-id: "{{ item.spot_request.spot_instance_request_id }}"
361+
loop: "{{ ec2_spot_request_result.results }}"
362+
loop_control:
363+
index_var: idx
364+
label: "{{ server_name | lower }}{{ '%02d' % (idx + 1) }}"
365+
register: ec2_spot_instance_wait_result
366+
until:
367+
- ec2_spot_instance_wait_result.instances[0][ip_address_type] is defined
368+
- ec2_spot_instance_wait_result.instances[0][ip_address_type] | length > 0
369+
retries: 12
370+
delay: 10
371+
when: item.spot_request.spot_instance_request_id is defined
372+
354373
- name: "AWS: Rename the EC2 Spot instance"
355374
amazon.aws.ec2_instance:
356375
access_key: "{{ lookup('ansible.builtin.env', 'AWS_ACCESS_KEY_ID') }}"
@@ -364,9 +383,7 @@
364383
index_var: idx
365384
label: "{{ server_name | lower }}{{ '%02d' % (idx + 1) }}"
366385
register: ec2_spot_instance_result
367-
until:
368-
- ec2_spot_instance_result.instances[0][ip_address_type] is defined
369-
- ec2_spot_instance_result.instances[0][ip_address_type] | length > 0
386+
until: ec2_spot_instance_result is success
370387
retries: 3
371388
delay: 10
372389
when: item.spot_request.spot_instance_request_id is defined

0 commit comments

Comments
 (0)