|
47 | 47 | plat__aws_xaccount_external_id: "{{ plat__cdp_xaccount_external_id }}" |
48 | 48 | plat__aws_xaccount_account_id: "{{ plat__cdp_xaccount_account_id }}" |
49 | 49 |
|
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 or established by Infrastructure |
| 52 | + when: plat__aws_vpc_id == "" and infra__aws_vpc_id is undefined |
53 | 53 | block: |
54 | | - - name: Query AWS VPC |
| 54 | + - name: Query AWS VPC by name |
55 | 55 | amazon.aws.ec2_vpc_net_info: |
56 | 56 | region: "{{ plat__region }}" |
57 | 57 | filters: |
|
63 | 63 | ansible.builtin.set_fact: |
64 | 64 | plat__aws_vpc_id: "{{ __aws_vpc_info.vpcs[0].id }}" |
65 | 65 |
|
66 | | -- name: Set fact for AWS VPC ID by assignment |
67 | | - when: infra__aws_vpc_id is defined |
| 66 | +- name: Set fact for AWS VPC ID if established by Infrastructure |
| 67 | + when: plat__aws_vpc_id == "" and infra__aws_vpc_id is defined |
68 | 68 | ansible.builtin.set_fact: |
69 | 69 | plat__aws_vpc_id: "{{ infra__aws_vpc_id }}" |
70 | 70 |
|
71 | | -- name: Discover AWS VPC Subnets |
72 | | - when: infra__aws_subnet_ids is undefined |
| 71 | +- name: Handle AWS Subnet IDs if not defined |
| 72 | + when: not plat__aws_public_subnet_ids or not plat__aws_private_subnet_ids # Defaults are empty lists |
73 | 73 | block: |
74 | 74 | - name: Query AWS Subnets |
75 | 75 | amazon.aws.ec2_vpc_subnet_info: |
76 | 76 | region: "{{ plat__region }}" |
77 | 77 | filters: |
78 | | - "tag:Name": "{{ plat__namespace }}" |
| 78 | + vpc-id: "{{ plat__aws_vpc_id }}" |
79 | 79 | register: __aws_subnets_info |
80 | 80 |
|
81 | | - - name: Set fact for AWS Subnet IDs |
82 | | - when: __aws_subnets_info is defined |
| 81 | + - name: Assert discovered AWS Subnets |
| 82 | + ansible.builtin.assert: |
| 83 | + that: __aws_subnets_info.subnets | length > 0 |
| 84 | + fail_msg: "No subnets discovered for AWS VPC" |
| 85 | + quiet: yes |
| 86 | + |
| 87 | + - name: Set fact for AWS Public Subnet IDs if established by Infrastructure |
| 88 | + when: not plat__aws_public_subnet_ids and infra__aws_public_subnet_ids is defined |
| 89 | + ansible.builtin.set_fact: |
| 90 | + plat__aws_public_subnet_ids: "{{ infra__aws_public_subnet_ids }}" |
| 91 | + |
| 92 | + - name: Discover AWS VPC Public Subnets |
| 93 | + when: not plat__aws_public_subnet_ids and infra__aws_public_subnet_ids is undefined |
83 | 94 | ansible.builtin.set_fact: |
84 | | - plat__aws_subnet_ids: "{{ plat__aws_subnet_ids | default([]) | union([__aws_subnet_item.subnet.id | default('')]) }}" |
| 95 | + __aws_public_subnet_ids: "{{ __aws_public_subnet_ids | default([]) | union([__aws_subnet_item.subnet_id | default('')]) }}" |
85 | 96 | loop_control: |
86 | 97 | loop_var: __aws_subnet_item |
87 | | - label: "{{ __aws_subnet_item.subnet.id }}" |
88 | | - loop: "{{ __aws_subnets_info.subnets }}" |
| 98 | + label: "{{ __aws_subnet_item.subnet_id }}" |
| 99 | + loop: "{{ __aws_subnets_info.subnets | selectattr('map_public_ip_on_launch') }}" |
89 | 100 |
|
90 | | -- name: Set fact for AWS Subnet IDs by assignment |
91 | | - when: infra__aws_subnet_ids is defined |
92 | | - ansible.builtin.set_fact: |
93 | | - plat__aws_subnet_ids: "{{ infra__aws_subnet_ids }}" |
| 101 | + - name: Set fact for AWS Private Subnet IDs if established by Infrastructure |
| 102 | + when: not plat__aws_private_subnet_ids and infra__aws_private_subnet_ids is defined |
| 103 | + ansible.builtin.set_fact: |
| 104 | + plat__aws_private_subnet_ids: "{{ infra__aws_private_subnet_ids }}" |
| 105 | + |
| 106 | + - name: Discover AWS VPC Private Subnets |
| 107 | + when: not plat__aws_private_subnet_ids and infra__aws_private_subnet_ids is undefined |
| 108 | + ansible.builtin.set_fact: |
| 109 | + __aws_private_subnet_ids: "{{ __aws_private_subnet_ids | default([]) | union([__aws_subnet_item.subnet_id | default('')]) }}" |
| 110 | + loop_control: |
| 111 | + loop_var: __aws_subnet_item |
| 112 | + label: "{{ __aws_subnet_item.subnet_id }}" |
| 113 | + loop: "{{ __aws_subnets_info.subnets | rejectattr('map_public_ip_on_launch') }}" |
| 114 | + |
| 115 | + - name: Set fact for AWS VPC Subnets |
| 116 | + ansible.builtin.set_fact: |
| 117 | + plat__aws_public_subnet_ids: "{{ __aws_public_subnet_ids | default([]) }}" |
| 118 | + plat__aws_private_subnet_ids: "{{ __aws_private_subnet_ids | default([]) }}" |
94 | 119 |
|
95 | | -# TODO: Discover AWS VPC Public Subnets if infra__ is not present |
96 | | -- name: Set public subnets for public endpoint access |
97 | | - when: plat__public_endpoint_access |
| 120 | +- name: Set fact for AWS Subnet IDs |
98 | 121 | ansible.builtin.set_fact: |
99 | | - plat__aws_public_subnet_ids: "{{ infra__aws_public_subnet_ids }}" |
100 | | - plat__endpoint_access_scheme: "PUBLIC" |
| 122 | + plat__aws_subnet_ids: "{{ plat__aws_public_subnet_ids | union(plat__aws_private_subnet_ids) }}" |
101 | 123 |
|
| 124 | +# TODO Collapse the two SG queries together |
102 | 125 | - name: Discover AWS Security Group for Knox |
103 | 126 | when: infra__aws_security_group_knox_id is undefined |
104 | 127 | block: |
105 | 128 | - name: Query AWS Security Group for Knox |
106 | 129 | amazon.aws.ec2_group_info: |
107 | 130 | region: "{{ plat__region }}" |
108 | 131 | filters: |
| 132 | + vpc-id: "{{ plat__aws_vpc_id }}" |
109 | 133 | group-name: "{{ plat__security_group_knox_name }}" |
110 | 134 | register: __aws_security_group_knox_info |
111 | 135 |
|
|
126 | 150 | amazon.aws.ec2_group_info: |
127 | 151 | region: "{{ plat__region }}" |
128 | 152 | filters: |
| 153 | + vpc-id: "{{ plat__aws_vpc_id }}" |
129 | 154 | group-name: "{{ plat__security_group_default_name }}" |
130 | 155 | register: __aws_security_group_default_info |
131 | 156 |
|
|
0 commit comments