Skip to content

Commit

Permalink
select available zone
Browse files Browse the repository at this point in the history
  • Loading branch information
abikouo committed Jul 3, 2024
1 parent ba4aa9f commit 14e86ac
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
# - instance_creation is failed
# - '"You are not authorized to perform this operation." in instance_creation.msg'

- ansible.builtin.include_tasks: select_availability_zone.yml

- name: New instance with dedicated tenancy
amazon.aws.ec2_instance:
state: running
Expand All @@ -58,7 +60,7 @@
TestId: "{{ ec2_instance_tag_TestId }}"
security_group: default
instance_type: "{{ ec2_instance_type }}"
availability_zone: us-east-1c
availability_zone: "{{ ec2_availability_zone }}"
wait: true
ignore_errors: true
register: instance_creation
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
- name: List available AZs in current Region
amazon.aws.aws_az_info:
register: region_azs

- ansible.builtin.set_fact:
av_zones: "{{ region_azs.availability_zones | map(attribute='zone_name') | list }}"

- name: List t3.micro instances
amazon.aws.ec2_instance_info:
filters:
instance-type: t3.micro
instance-state-name:
- pending
- running
register: _instances

- ansible.builtin.set_fact:
instances_zones: "{{ _instances.instances | map(attribute='placement.availability_zone') | list }}"

- ansible.builtin.set_fact:
ec2_availability_zone: "{{ av_zones | ansible.builtin.difference(instances_zones) | list | ansible.builtin.random }}"

0 comments on commit 14e86ac

Please sign in to comment.