Skip to content

Commit dfda24a

Browse files
wmudgeChaffelson
andauthored
Fix AWS network discovery (#72)
* Fix bug where AWS subnets not being collected for platform deployment on AWS * Remove redundant setting of infra__aws_private_subnet_ids in infra * Filter subnets by VPC, not by name * Add VPC discovery assertion * Update assignment and discovery to match process within runtime role * Add missing shared AWS networking parameters * Fix result label for AWS VPC discovery Signed-off-by: Webster Mudge <wmudge@cloudera.com> Co-authored-by: Daniel Chaffelson <chaffelson@gmail.com>
1 parent 9e513ae commit dfda24a

File tree

5 files changed

+37
-13
lines changed

5 files changed

+37
-13
lines changed

roles/common/defaults/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ common__data_path: "{{ infra.storage.path.data | default(
8787
common__ranger_audit_path: "{{ infra.storage.path.ranger_audit | default('ranger/audit') }}"
8888

8989
# AWS Infra
90+
common__aws_vpc_id: "{{ infra.aws.vpc.existing.vpc_id | default('') }}"
91+
common__aws_public_subnet_ids: "{{ infra.aws.vpc.existing.public_subnet_ids | default([]) }}"
92+
common__aws_private_subnet_ids: "{{ infra.aws.vpc.existing.private_subnet_ids | default([]) }}"
9093
common__aws_region: "{{ infra.aws.region | default('eu-west-1') }}"
9194
common__aws_profile: "{{ infra.aws.profile | default('') }}"
9295
common__aws_role_suffix: "{{ infra.aws.role.suffix | default(common__role_suffix) }}"

roles/infrastructure/tasks/initialize_aws.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767

6868
- name: Set facts for existing AWS Private Subnet IDs and associate VPC ID
6969
ansible.builtin.set_fact:
70-
infra__aws_private_subnet_ids: "{{ infra__aws_private_subnet_ids }}"
7170
infra__aws_subnet_ids: "{{ infra__aws_private_subnet_ids }}"
7271
infra__aws_vpc_id: "{{ __aws_private_subnets_info.subnets | map(attribute='vpc_id') | list | first }}"
7372

roles/platform/defaults/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ plat__cdp_xaccount_external_id: "{{ env.cdp.cross_account.external
9292
plat__cdp_xaccount_account_id: "{{ env.cdp.cross_account.account_id | default(False) }}"
9393

9494
# AWS
95+
plat__aws_vpc_id: "{{ common__aws_vpc_id }}"
96+
plat__aws_public_subnet_ids: "{{ common__aws_public_subnet_ids }}"
97+
plat__aws_private_subnet_ids: "{{ common__aws_private_subnet_ids }}"
98+
9599
plat__aws_role_suffix: "{{ common__aws_role_suffix }}"
96100
plat__aws_policy_suffix: "{{ env.aws.policy.suffix | default(common__policy_suffix) }}"
97101
plat__aws_storage_suffix: "{{ env.aws.storage.suffix | default(common__storage_suffix) }}"

roles/platform/tasks/initialize_setup_aws.yml

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,35 +47,42 @@
4747
plat__aws_xaccount_external_id: "{{ plat__cdp_xaccount_external_id }}"
4848
plat__aws_xaccount_account_id: "{{ plat__cdp_xaccount_account_id }}"
4949

50-
# TODO - Confirm the two following tasks are the design pattern we want: checking for a set_fact from another role before establishing its own role fact
51-
- name: Discover AWS VPC
52-
when: infra__aws_vpc_id is undefined
50+
# Runlevel first, upstream second, and discover third
51+
- name: Discover AWS VPC if not defined
52+
when: plat__aws_vpc_id == "" and infra__aws_vpc_id is undefined
5353
block:
54-
- name: Query AWS VPC
54+
- name: Query AWS VPC by name
5555
amazon.aws.ec2_vpc_net_info:
5656
region: "{{ plat__region }}"
5757
filters:
5858
"tag:Name": "{{ plat__vpc_name }}"
5959
register: __aws_vpc_info
6060

61+
- name: Assert discovered AWS VPC
62+
ansible.builtin.assert:
63+
that: __aws_vpc_info.vpcs | length == 1
64+
fail_msg: "No AWS VPC discovered"
65+
quiet: yes
66+
6167
- name: Set fact for AWS VPC ID
6268
when: __aws_vpc_info is defined
6369
ansible.builtin.set_fact:
6470
plat__aws_vpc_id: "{{ __aws_vpc_info.vpcs[0].id }}"
6571

66-
- name: Set fact for AWS VPC ID by assignment
72+
- name: Set fact for AWS VPC ID if established by Infrastructure
6773
when: infra__aws_vpc_id is defined
6874
ansible.builtin.set_fact:
6975
plat__aws_vpc_id: "{{ infra__aws_vpc_id }}"
7076

71-
- name: Discover AWS VPC Subnets
72-
when: infra__aws_subnet_ids is undefined
77+
# Runlevel first, upstream second, and discover third
78+
- name: Handle AWS Public and Private VPC Subnets if not defined
79+
when: not plat__aws_public_subnet_ids or not plat__aws_private_subnet_ids
7380
block:
7481
- name: Query AWS Subnets
7582
amazon.aws.ec2_vpc_subnet_info:
7683
region: "{{ plat__region }}"
7784
filters:
78-
"tag:Name": "{{ plat__namespace }}"
85+
vpc-id: "{{ plat__aws_vpc_id }}"
7986
register: __aws_subnets_info
8087

8188
- name: Assert discovered AWS Subnets
@@ -120,15 +127,20 @@
120127
label: "{{ __aws_subnet_item.subnet_id }}"
121128
loop: "{{ __aws_subnets_info.subnets | rejectattr('map_public_ip_on_launch') }}"
122129

123-
- name: Set fact for AWS Private Subnet IDs
130+
- name: Set fact for AWS Private Subnet IDs
124131
ansible.builtin.set_fact:
125132
plat__aws_private_subnet_ids: "{{ __aws_private_subnet_ids | default([]) }}"
126133

127-
# TODO: Discover AWS VPC Public Subnets if infra__ is not present
134+
- name: Set fact for AWS Subnet IDs and define generic subnet IDs
135+
ansible.builtin.set_fact:
136+
plat__aws_subnet_ids: "{{ plat__aws_public_subnet_ids | union(plat__aws_private_subnet_ids) }}"
137+
plat__public_subnet_ids: "{{ plat__aws_public_subnet_ids }}"
138+
plat__private_subnet_ids: "{{ plat__aws_private_subnet_ids }}"
139+
140+
# TODO: Move endpoint access scheme to instantiation section
128141
- name: Set public subnets for public endpoint access
129142
when: plat__public_endpoint_access
130143
ansible.builtin.set_fact:
131-
plat__aws_public_subnet_ids: "{{ infra__aws_public_subnet_ids }}"
132144
plat__endpoint_access_scheme: "PUBLIC"
133145

134146
- name: Discover AWS Security Group for Knox

roles/runtime/tasks/initialize_setup_aws.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
"tag:Name": "{{ run__vpc_name }}"
2626
register: __aws_vpc_info
2727

28+
- name: Assert discovered AWS VPC
29+
ansible.builtin.assert:
30+
that: __aws_vpc_info.vpcs | length == 1
31+
fail_msg: "No AWS VPC discovered"
32+
quiet: yes
33+
2834
- name: Set fact for AWS VPC ID
2935
when: __aws_vpc_info is defined
3036
ansible.builtin.set_fact:
@@ -107,7 +113,7 @@
107113
ansible.builtin.set_fact:
108114
run__aws_private_subnet_ids: "{{ __aws_private_subnet_ids | default([]) }}"
109115

110-
- name: Set fact for AWS Subnet IDs
116+
- name: Set fact for AWS Subnet IDs and define generic subnet IDs
111117
ansible.builtin.set_fact:
112118
run__aws_subnet_ids: "{{ run__aws_public_subnet_ids | union(run__aws_private_subnet_ids) }}"
113119
run__public_subnet_ids: "{{ run__aws_public_subnet_ids }}"

0 commit comments

Comments
 (0)