Skip to content

Commit c75366e

Browse files
authored
Ec2 subnet lookup pr 1.x (#589)
* First pass at EC2 subnet detection. * Touching subnet file to ensure it exists. * Trying a different approach, file module didn't work. * Switching back to file module. * We need to create the directory for new servers too. * Bad variable name. * Changing subnet lookup order to check for defined subnet first.
1 parent f61e540 commit c75366e

File tree

1 file changed

+6
-6
lines changed
  • roles/aws/aws_ec2_with_eip/tasks

1 file changed

+6
-6
lines changed

roles/aws/aws_ec2_with_eip/tasks/main.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434
ansible.builtin.set_fact:
3535
_aws_ec2_with_eip_vpc_subnet_id: "{{ lookup('file', _ce_provision_data_dir + '/' + _aws_resource_name + '/ec2-subnet-id') }}"
3636

37+
# If we have no stored subnet ID and one has been set in variables this will override whatever might be looked up.
38+
- name: Load defined subnet from variables.
39+
ansible.builtin.set_fact:
40+
_aws_ec2_with_eip_vpc_subnet_id: "{{ aws_ec2_with_eip.vpc_subnet_id }}"
41+
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 )
42+
3743
# If we have no stored subnet ID and vpc_name is defined we'll look up available subnets
3844
- name: Gather VPC information.
3945
amazon.aws.ec2_vpc_net_info:
@@ -66,12 +72,6 @@
6672
with_random_choice: "{{ _aws_ec2_with_eip_subnets.subnets }}"
6773
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 )
6874

69-
# If we have no stored subnet ID and one has been set in variables this will override whatever might be looked up.
70-
- name: Load defined subnet from variables.
71-
ansible.builtin.set_fact:
72-
_aws_ec2_with_eip_vpc_subnet_id: "{{ aws_ec2_with_eip.vpc_subnet_id }}"
73-
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 )
74-
7575
# Save the subnet ID to file.
7676
- name: Save the subnet ID in the data directory.
7777
ansible.builtin.template:

0 commit comments

Comments
 (0)