Skip to content
This repository was archived by the owner on Oct 7, 2025. It is now read-only.
12 changes: 6 additions & 6 deletions roles/aws/aws_ec2_with_eip/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
ansible.builtin.set_fact:
_aws_ec2_with_eip_vpc_subnet_id: "{{ lookup('file', _ce_provision_data_dir + '/' + _aws_resource_name + '/ec2-subnet-id') }}"

# If we have no stored subnet ID and one has been set in variables this will override whatever might be looked up.
- name: Load defined subnet from variables.
ansible.builtin.set_fact:
_aws_ec2_with_eip_vpc_subnet_id: "{{ aws_ec2_with_eip.vpc_subnet_id }}"
when: ( aws_ec2_with_eip.vpc_subnet_id is defined and aws_ec2_with_eip.vpc_subnet_id | length > 0 and _aws_ec2_with_eip_vpc_subnet_id | length == 0 )

# If we have no stored subnet ID and vpc_name is defined we'll look up available subnets
- name: Gather VPC information.
amazon.aws.ec2_vpc_net_info:
Expand Down Expand Up @@ -66,12 +72,6 @@
with_random_choice: "{{ _aws_ec2_with_eip_subnets.subnets }}"
when: ( aws_ec2_with_eip.vpc_name is defined and aws_ec2_with_eip.vpc_name | length > 0 and _aws_ec2_with_eip_vpc_subnet_id | length == 0 )

# If we have no stored subnet ID and one has been set in variables this will override whatever might be looked up.
- name: Load defined subnet from variables.
ansible.builtin.set_fact:
_aws_ec2_with_eip_vpc_subnet_id: "{{ aws_ec2_with_eip.vpc_subnet_id }}"
when: ( aws_ec2_with_eip.vpc_subnet_id is defined and aws_ec2_with_eip.vpc_subnet_id | length > 0 and _aws_ec2_with_eip_vpc_subnet_id | length == 0 )

# Save the subnet ID to file.
- name: Save the subnet ID in the data directory.
ansible.builtin.template:
Expand Down