Skip to content
This repository has been archived by the owner on May 28, 2024. It is now read-only.

Commit

Permalink
test: get one available instance type in zone before deploy instance
Browse files Browse the repository at this point in the history
Signed-off-by: Xiaofeng Wang <[email protected]>
  • Loading branch information
henrywang committed May 23, 2024
1 parent 73b144c commit 6d71337
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions playbooks/deploy-aws.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"0": t4g.medium
"1": c7g.medium
"2": m6g.medium
aws_region: "{{ lookup('env', 'AWS_REGION') | default('us-west-2', true) }}"

tasks:
- set_fact:
Expand Down Expand Up @@ -104,6 +105,27 @@
deploy_by_bib: "false"
when: ami_id == ""

- name: "{{ random_instance_type }} is available in zone {{ aws_region }}a"
shell:
aws ec2 describe-instance-type-offerings \
--location-type availability-zone \
--filters "Name=instance-type,Values={{ random_instance_type }}" "Name=location,Values={{ aws_region }}a" \
--query "InstanceTypeOfferings"
register: result_instance_type_available

- name: "get available instance type in zone {{ aws_region }}a"
shell:
aws ec2 describe-instance-type-offerings \
--location-type availability-zone \
--filters "Name=instance-type,Values={{ instance_type[arch]["0"] }},{{ instance_type[arch]["1"] }},{{ instance_type[arch]["2"] }}" "Name=location,Values={{ aws_region }}a" \
--query "InstanceTypeOfferings" | jq -r '.[0].InstanceType'
register: result_instance_type
when: result_instance_type_available.stdout == '[]'

- set_fact:
random_instance_type: "{{ result_instance_type.stdout }}"
when: result_instance_type_available.stdout == '[]'

- name: generate ec2_run_instance script
template:
src: ec2_run_instance.j2
Expand Down

0 comments on commit 6d71337

Please sign in to comment.