|
143 | 143 | ansible.builtin.set_fact: |
144 | 144 | default_ip_range: >- |
145 | 145 | {{ |
146 | | - vpc_info.data |
| 146 | + vpc_info.get('data', []) |
147 | 147 | | selectattr('region', 'equalto', server_location) |
148 | 148 | | selectattr('default', 'equalto', true) |
149 | 149 | | map(attribute='ip_range') |
150 | 150 | | first |
151 | 151 | }} |
152 | 152 | when: |
153 | 153 | - server_network | length < 1 |
154 | | - - vpc_info.data | selectattr('region', 'equalto', server_location) | selectattr('default', 'equalto', true) | list | length > 0 |
| 154 | + - vpc_info.get('data', []) | selectattr('region', 'equalto', server_location) | selectattr('default', 'equalto', true) | list | length > 0 |
155 | 155 |
|
156 | 156 | # if server_network is not specified and there is no default VPC, create a network |
157 | 157 | - name: "DigitalOcean: Create a VPC '{{ digital_ocean_vpc_name | default('network-' + server_location | default('')) }}'" |
|
163 | 163 | register: digital_ocean_vpc |
164 | 164 | when: |
165 | 165 | - server_network | length < 1 |
166 | | - - vpc_info.data | selectattr('region', 'equalto', server_location) | selectattr('default', 'equalto', true) | list | length == 0 |
| 166 | + - vpc_info.get('data', []) | selectattr('region', 'equalto', server_location) | selectattr('default', 'equalto', true) | list | length == 0 |
167 | 167 |
|
168 | 168 | - name: "Set variable: server_network" |
169 | 169 | ansible.builtin.set_fact: |
170 | 170 | server_network: "{{ digital_ocean_vpc_name | default('network-' + server_location) }}" |
171 | | - when: digital_ocean_vpc is changed |
| 171 | + when: |
| 172 | + - digital_ocean_vpc is defined |
| 173 | + - digital_ocean_vpc is changed |
172 | 174 |
|
173 | 175 | - name: "DigitalOcean: Gather information about VPC" |
174 | 176 | community.digitalocean.digital_ocean_vpc_info: |
175 | 177 | oauth_token: "{{ lookup('ansible.builtin.env', 'DO_API_TOKEN') }}" |
176 | 178 | register: vpc_info |
177 | | - when: digital_ocean_vpc is changed |
| 179 | + when: |
| 180 | + - digital_ocean_vpc is defined |
| 181 | + - digital_ocean_vpc is changed |
178 | 182 |
|
179 | 183 | # if server_network is specified |
180 | 184 | - name: "Fail if no VPC found in the specified region" |
181 | 185 | ansible.builtin.fail: |
182 | 186 | msg: "No VPC found with name '{{ server_network }}' in region '{{ server_location }}'" |
183 | 187 | when: |
184 | 188 | - server_network | length > 0 |
185 | | - - vpc_info.data | selectattr('region', 'equalto', server_location) | selectattr('name', 'equalto', server_network) | list | length == 0 |
| 189 | + - (vpc_info.get('data', []) |
| 190 | + | selectattr('region', 'equalto', server_location) |
| 191 | + | selectattr('name', 'equalto', server_network) |
| 192 | + | list |
| 193 | + | length |
| 194 | + ) == 0 |
186 | 195 |
|
187 | 196 | - name: Extract ip_range from VPC "{{ server_network | default('') }}" |
188 | 197 | ansible.builtin.set_fact: |
189 | 198 | vpc_ip_range: >- |
190 | 199 | {{ |
191 | | - vpc_info.data |
| 200 | + vpc_info.get('data', []) |
192 | 201 | | selectattr('region', 'equalto', server_location) |
193 | 202 | | selectattr('name', 'equalto', server_network) |
194 | 203 | | map(attribute='ip_range') |
|
200 | 209 | ansible.builtin.set_fact: |
201 | 210 | vpc_id: >- |
202 | 211 | {{ |
203 | | - vpc_info.data |
| 212 | + vpc_info.get('data', []) |
204 | 213 | | selectattr('region', 'equalto', server_location) |
205 | 214 | | selectattr('name', 'equalto', server_network) |
206 | 215 | | map(attribute='id') |
|
0 commit comments