diff --git a/playbooks/deploy-aws.yaml b/playbooks/deploy-aws.yaml index 4741fc5..84ce7f0 100644 --- a/playbooks/deploy-aws.yaml +++ b/playbooks/deploy-aws.yaml @@ -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: @@ -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