Debian Codegraph @

ansible_collections/amazon/aws/tests/integration/targets/elb_application_lb/tasks/main.yml

raw
1 ---
2 - name: Elb_application_lb integration tests
3 module_defaults:
4 group/aws:
5 access_key: "{{ aws_access_key }}"
6 secret_key: "{{ aws_secret_key }}"
7 session_token: "{{ security_token | default(omit) }}"
8 region: "{{ aws_region }}"
9 block:
10 - name: Create a test VPC
11 amazon.aws.ec2_vpc_net:
12 cidr_block: "{{ vpc_cidr }}"
13 name: "{{ resource_prefix }}_vpc"
14 state: present
15 ipv6_cidr: true
16 tags:
17 Name: elb_application_lb testing
18 ResourcePrefix: "{{ resource_prefix }}"
19 register: vpc
20 - name: "Set fact: VPC ID"
21 ansible.builtin.set_fact:
22 vpc_id: "{{ vpc.vpc.id }}"
23 - name: Get VPC's default security group
24 amazon.aws.ec2_security_group_info:
25 filters:
26 vpc-id: "{{ vpc_id }}"
27 register: default_sg
28 - name: Create an internet gateway
29 amazon.aws.ec2_vpc_igw:
30 vpc_id: "{{ vpc_id }}"
31 state: present
32 tags:
33 Name: "{{ resource_prefix }}"
34 register: igw
35 - name: Create private subnets
36 amazon.aws.ec2_vpc_subnet:
37 cidr: "{{ item.cidr }}"
38 az: "{{ aws_region }}{{ item.az }}"
39 vpc_id: "{{ vpc_id }}"
40 state: present
41 tags:
42 Public: "False"
43 Name: private-{{ item.az }}
44 with_items:
45 - cidr: "{{ private_subnet_cidr_1 }}"
46 az: a
47 - cidr: "{{ private_subnet_cidr_2 }}"
48 az: b
49 register: private_subnets
50 - name: Create public subnets with ipv6
51 amazon.aws.ec2_vpc_subnet:
52 cidr: "{{ item.cidr }}"
53 az: "{{ aws_region }}{{ item.az }}"
54 vpc_id: "{{ vpc_id }}"
55 state: present
56 ipv6_cidr: "{{ item.vpc_ipv6_cidr }}"
57 tags:
58 Public: "True"
59 Name: public-{{ item.az }}
60 with_items:
61 - cidr: "{{ public_subnet_cidr_1 }}"
62 az: a
63 vpc_ipv6_cidr: "{{ vpc.vpc.ipv6_cidr_block_association_set[0].ipv6_cidr_block | replace('0::/56', '0::/64') }}"
64 - cidr: "{{ public_subnet_cidr_2 }}"
65 az: b
66 vpc_ipv6_cidr: "{{ vpc.vpc.ipv6_cidr_block_association_set[0].ipv6_cidr_block | replace('0::/56', '1::/64') }}"
67 register: public_subnets
68 - name: Create list of subnet ids
69 ansible.builtin.set_fact:
70 public_subnets: "{{ public_subnets.results | map(attribute='subnet') | map(attribute='id') }}"
71 private_subnets: "{{ private_subnets.results | map(attribute='subnet') | map(attribute='id') }}"
72 - name: Create a route table
73 amazon.aws.ec2_vpc_route_table:
74 vpc_id: "{{ vpc_id }}"
75 tags:
76 Name: igw-route
77 Created: "{{ resource_prefix }}"
78 subnets: "{{ public_subnets + private_subnets }}"
79 routes:
80 - dest: "0.0.0.0/0"
81 gateway_id: "{{ igw.gateway_id }}"
82 register: route_table
83 - name: Create a security group for Ansible ALB integration tests
84 amazon.aws.ec2_security_group:
85 name: "{{ resource_prefix }}"
86 description: security group for Ansible ALB integration tests
87 state: present
88 vpc_id: "{{ vpc_id }}"
89 rules:
90 - proto: tcp
91 from_port: 1
92 to_port: 65535
93 cidr_ip: "0.0.0.0/0"
94 register: sec_group
95 - name: Create another security group for Ansible ALB integration tests
96 amazon.aws.ec2_security_group:
97 name: "{{ resource_prefix }}-2"
98 description: security group for Ansible ALB integration tests
99 state: present
100 vpc_id: "{{ vpc_id }}"
101 rules:
102 - proto: tcp
103 from_port: 1
104 to_port: 65535
105 cidr_ip: "0.0.0.0/0"
106 register: sec_group2
107 - name: Create a target group for testing
108 community.aws.elb_target_group:
109 name: "{{ tg_name }}"
110 protocol: http
111 port: 80
112 vpc_id: "{{ vpc_id }}"
113 state: present
114 register: tg
115 - name: Create a second target group for testing
116 community.aws.elb_target_group:
117 name: "{{ tg_2_name }}"
118 protocol: http
119 port: 80
120 vpc_id: "{{ vpc_id }}"
121 state: present
122 register: tg_2
123 - name: Get ARN of calling user
124 amazon.aws.aws_caller_info:
125 register: aws_caller_info
126 - name: Register account id
127 ansible.builtin.set_fact:
128 aws_account: "{{ aws_caller_info.account }}"
129 - name: Create S3 bucket for testing
130 amazon.aws.s3_bucket:
131 name: "{{ s3_bucket_name }}"
132 state: present
133 encryption: aws:kms
134 policy: "{{ lookup('template', 'policy.json') }}"
135
136 - name: Run tests for creating ALB with listener having multiple certificates
137 ansible.builtin.import_tasks: alb_with_multiple_listener_certs.yml
138
139 - name: Run tests for creating ALB with listener rules on initial creation
140 ansible.builtin.import_tasks: alb_with_rules_on_create.yml
141
142 - name: Run tests for ALB with multiple default actions (issue 2537)
143 ansible.builtin.import_tasks: alb_with_multiple_default_actions.yml
144
145 - name: Create an ALB (invalid - SslPolicy is required when Protocol == HTTPS)
146 amazon.aws.elb_application_lb:
147 name: "{{ alb_name }}"
148 subnets: "{{ public_subnets }}"
149 security_groups: "{{ sec_group.group_id }}"
150 state: present
151 listeners:
152 - Protocol: HTTPS
153 Port: 80
154 DefaultActions:
155 - Type: forward
156 TargetGroupName: "{{ tg_name }}"
157 ignore_errors: true # noqa: ignore-errors
158 register: alb
159 - ansible.builtin.assert:
160 that:
161 - alb is failed
162 - alb.msg is match("'SslPolicy' is a required listener dict key when Protocol = HTTPS")
163
164 - name: Create an ALB (invalid - didn't provide required listener options)
165 amazon.aws.elb_application_lb:
166 name: "{{ alb_name }}"
167 subnets: "{{ public_subnets }}"
168 security_groups: "{{ sec_group.group_id }}"
169 state: present
170 listeners:
171 - Port: 80
172 ignore_errors: true # noqa: ignore-errors
173 register: alb
174 - ansible.builtin.assert:
175 that:
176 - alb is failed
177 - alb.msg is match("missing required arguments:\ DefaultActions, Protocol found in listeners")
178
179 - name: Create an ALB (invalid - invalid listener option type)
180 amazon.aws.elb_application_lb:
181 name: "{{ alb_name }}"
182 subnets: "{{ public_subnets }}"
183 security_groups: "{{ sec_group.group_id }}"
184 state: present
185 listeners:
186 - Protocol: HTTP
187 Port: bad type
188 DefaultActions:
189 - Type: forward
190 TargetGroupName: "{{ tg_name }}"
191 ignore_errors: true # noqa: ignore-errors
192 register: alb
193 - ansible.builtin.assert:
194 that:
195 - alb is failed
196 - "'unable to convert to int' in alb.msg"
197
198 - name: Create an ALB (invalid - invalid ip address type)
199 amazon.aws.elb_application_lb:
200 name: "{{ alb_name }}"
201 subnets: "{{ public_subnets }}"
202 security_groups: "{{ sec_group.group_id }}"
203 state: present
204 listeners:
205 - Protocol: HTTP
206 Port: 80
207 DefaultActions:
208 - Type: forward
209 TargetGroupName: "{{ tg_name }}"
210 ip_address_type: ip_addr_v4_v6
211 ignore_errors: true # noqa: ignore-errors
212 register: alb
213 - ansible.builtin.assert:
214 that:
215 - alb is failed
216
217 # ------------------------------------------------------------------------------------------
218
219 - name: Create an ALB with defaults - check_mode
220 amazon.aws.elb_application_lb:
221 name: "{{ alb_name }}"
222 subnets: "{{ public_subnets }}"
223 security_groups: []
224 state: present
225 listeners:
226 - Protocol: HTTP
227 Port: 80
228 DefaultActions:
229 - Type: forward
230 TargetGroupName: "{{ tg_name }}"
231 register: alb
232 check_mode: true
233 - ansible.builtin.assert:
234 that:
235 - alb is changed
236 - alb.msg is match('Would have created ALB if not in check mode.')
237
238 - name: Create an ALB with defaults
239 amazon.aws.elb_application_lb:
240 name: "{{ alb_name }}"
241 subnets: "{{ public_subnets }}"
242 security_groups: []
243 state: present
244 listeners:
245 - Protocol: HTTP
246 Port: 80
247 DefaultActions:
248 - Type: forward
249 TargetGroupName: "{{ tg_name }}"
250 register: alb
251 - ansible.builtin.assert:
252 that:
253 - alb is changed
254 - alb.listeners[0].rules | length == 1
255 - alb.security_groups | length == 1
256 - alb.security_groups[0] == default_sg.security_groups[0].group_id
257
258 - name: Create an ALB with defaults (idempotence) - check_mode
259 amazon.aws.elb_application_lb:
260 name: "{{ alb_name }}"
261 subnets: "{{ public_subnets }}"
262 security_groups: []
263 state: present
264 listeners:
265 - Protocol: HTTP
266 Port: 80
267 DefaultActions:
268 - Type: forward
269 TargetGroupName: "{{ tg_name }}"
270 register: alb
271 check_mode: true
272 - ansible.builtin.assert:
273 that:
274 - alb is not changed
275 - alb.msg is match('IN CHECK MODE - no changes to make to ALB specified.')
276
277 - name: Create an ALB with defaults (idempotence)
278 amazon.aws.elb_application_lb:
279 name: "{{ alb_name }}"
280 subnets: "{{ public_subnets }}"
281 security_groups: []
282 state: present
283 listeners:
284 - Protocol: HTTP
285 Port: 80
286 DefaultActions:
287 - Type: forward
288 TargetGroupName: "{{ tg_name }}"
289 register: alb
290 - ansible.builtin.assert:
291 that:
292 - alb is not changed
293 - alb.listeners[0].rules | length == 1
294 - alb.security_groups[0] == default_sg.security_groups[0].group_id
295
296 # ------------------------------------------------------------------------------------------
297
298 - name: Create an ALB with attributes - check_mode
299 amazon.aws.elb_application_lb:
300 name: "{{ alb_2_name }}"
301 subnets: "{{ public_subnets }}"
302 security_groups: "{{ sec_group.group_id }}"
303 state: present
304 listeners:
305 - Protocol: HTTP
306 Port: 80
307 DefaultActions:
308 - Type: forward
309 TargetGroupName: "{{ tg_2_name }}"
310 access_logs_enabled: true
311 access_logs_s3_bucket: "{{ s3_bucket_name }}"
312 access_logs_s3_prefix: alb-logs
313 ip_address_type: dualstack
314 http2: false
315 http_desync_mitigation_mode: monitor
316 http_drop_invalid_header_fields: true
317 http_x_amzn_tls_version_and_cipher_suite: true
318 http_xff_client_port: true
319 waf_fail_open: true
320 register: alb_2
321 check_mode: true
322
323 - name: Verify check mode response
324 ansible.builtin.assert:
325 that:
326 - alb_2 is changed
327 - alb_2.msg is match('Would have created ALB if not in check mode.')
328
329 - name: Create an ALB with attributes
330 amazon.aws.elb_application_lb:
331 name: "{{ alb_2_name }}"
332 subnets: "{{ public_subnets }}"
333 security_groups: "{{ sec_group.group_id }}"
334 state: present
335 listeners:
336 - Protocol: HTTP
337 Port: 80
338 DefaultActions:
339 - Type: forward
340 TargetGroupName: "{{ tg_2_name }}"
341 access_logs_enabled: true
342 access_logs_s3_bucket: "{{ s3_bucket_name }}"
343 access_logs_s3_prefix: alb-logs
344 http2: false
345 http_desync_mitigation_mode: monitor
346 http_drop_invalid_header_fields: true
347 http_x_amzn_tls_version_and_cipher_suite: true
348 http_xff_client_port: true
349 idle_timeout: 120
350 ip_address_type: dualstack
351 waf_fail_open: true
352 register: alb_2
353
354 - name: Verify ALB was created with correct attributes
355 ansible.builtin.assert:
356 that:
357 - alb_2 is changed
358 - alb_2.listeners[0].rules | length == 1
359 - alb_2.security_groups | length == 1
360 - alb_2.security_groups[0] == sec_group.group_id
361 - alb_2.ip_address_type == 'dualstack'
362 - alb_2.access_logs_s3_enabled | bool
363 - alb_2.access_logs_s3_bucket == s3_bucket_name
364 - alb_2.access_logs_s3_prefix == "alb-logs"
365 - not alb_2.routing_http2_enabled | bool
366 - alb_2.routing_http_desync_mitigation_mode == 'monitor'
367 - alb_2.routing_http_drop_invalid_header_fields_enabled | bool
368 - alb_2.routing_http_x_amzn_tls_version_and_cipher_suite_enabled | bool
369 - alb_2.routing_http_xff_client_port_enabled | bool
370 - alb_2.idle_timeout_timeout_seconds == "120"
371 - alb_2.waf_fail_open_enabled | bool
372
373 - name: Create an ALB with attributes (idempotence) - check_mode
374 amazon.aws.elb_application_lb:
375 name: "{{ alb_2_name }}"
376 subnets: "{{ public_subnets }}"
377 security_groups: "{{ sec_group.group_id }}"
378 state: present
379 listeners:
380 - Protocol: HTTP
381 Port: 80
382 DefaultActions:
383 - Type: forward
384 TargetGroupName: "{{ tg_2_name }}"
385 access_logs_enabled: true
386 access_logs_s3_bucket: "{{ s3_bucket_name }}"
387 access_logs_s3_prefix: alb-logs
388 ip_address_type: dualstack
389 http2: false
390 http_desync_mitigation_mode: monitor
391 http_drop_invalid_header_fields: true
392 http_x_amzn_tls_version_and_cipher_suite: true
393 http_xff_client_port: true
394 waf_fail_open: true
395 register: alb_2
396 check_mode: true
397
398 - name: Verify idempotence check mode response
399 ansible.builtin.assert:
400 that:
401 - alb_2 is not changed
402 - alb_2.msg is match('IN CHECK MODE - no changes to make to ALB specified.')
403
404 - name: Create an ALB with attributes (idempotence)
405 amazon.aws.elb_application_lb:
406 name: "{{ alb_2_name }}"
407 subnets: "{{ public_subnets }}"
408 security_groups: "{{ sec_group.group_id }}"
409 state: present
410 listeners:
411 - Protocol: HTTP
412 Port: 80
413 DefaultActions:
414 - Type: forward
415 TargetGroupName: "{{ tg_2_name }}"
416 access_logs_enabled: true
417 access_logs_s3_bucket: "{{ s3_bucket_name }}"
418 access_logs_s3_prefix: alb-logs
419 ip_address_type: dualstack
420 http2: false
421 http_desync_mitigation_mode: monitor
422 http_drop_invalid_header_fields: true
423 http_x_amzn_tls_version_and_cipher_suite: true
424 http_xff_client_port: true
425 waf_fail_open: true
426 register: alb_2
427
428 - name: Verify ALB was not changed
429 ansible.builtin.assert:
430 that:
431 - alb_2 is not changed
432 - alb_2.listeners[0].rules | length == 1
433 - alb_2.security_groups | length == 1
434 - alb_2.security_groups[0] == sec_group.group_id
435 - alb_2.ip_address_type == 'dualstack'
436 - alb_2.access_logs_s3_enabled | bool
437 - alb_2.access_logs_s3_bucket == s3_bucket_name
438 - alb_2.access_logs_s3_prefix == "alb-logs"
439 - not alb_2.routing_http2_enabled | bool
440 - alb_2.routing_http_desync_mitigation_mode == 'monitor'
441 - alb_2.routing_http_drop_invalid_header_fields_enabled | bool
442 - alb_2.routing_http_x_amzn_tls_version_and_cipher_suite_enabled | bool
443 - alb_2.routing_http_xff_client_port_enabled | bool
444 - alb_2.idle_timeout_timeout_seconds == "120"
445 - alb_2.waf_fail_open_enabled | bool
446
447 # ------------------------------------------------------------------------------------------
448
449 - name: Update an ALB with ip address type - check_mode
450 amazon.aws.elb_application_lb:
451 name: "{{ alb_name }}"
452 subnets: "{{ public_subnets }}"
453 security_groups: "{{ sec_group.group_id }}"
454 state: present
455 listeners:
456 - Protocol: HTTP
457 Port: 80
458 DefaultActions:
459 - Type: forward
460 TargetGroupName: "{{ tg_name }}"
461 ip_address_type: dualstack
462 register: alb
463 check_mode: true
464 - ansible.builtin.assert:
465 that:
466 - alb is changed
467 - alb.msg is match('Would have updated ALB if not in check mode.')
468
469 - name: Update an ALB with ip address type
470 amazon.aws.elb_application_lb:
471 name: "{{ alb_name }}"
472 subnets: "{{ public_subnets }}"
473 security_groups: "{{ sec_group.group_id }}"
474 state: present
475 listeners:
476 - Protocol: HTTP
477 Port: 80
478 DefaultActions:
479 - Type: forward
480 TargetGroupName: "{{ tg_name }}"
481 ip_address_type: dualstack
482 register: alb
483 - ansible.builtin.assert:
484 that:
485 - alb is changed
486 - alb.ip_address_type == 'dualstack'
487 - alb.listeners[0].rules | length == 1
488 - alb.routing_http2_enabled | bool
489 - alb.routing_http_desync_mitigation_mode == 'defensive'
490 - not alb.routing_http_drop_invalid_header_fields_enabled | bool
491 - not alb.routing_http_x_amzn_tls_version_and_cipher_suite_enabled | bool
492 - not alb.routing_http_xff_client_port_enabled | bool
493 - not alb.waf_fail_open_enabled | bool
494
495 - name: Create an ALB with ip address type (idempotence) - check_mode
496 amazon.aws.elb_application_lb:
497 name: "{{ alb_name }}"
498 subnets: "{{ public_subnets }}"
499 security_groups: "{{ sec_group.group_id }}"
500 state: present
501 listeners:
502 - Protocol: HTTP
503 Port: 80
504 DefaultActions:
505 - Type: forward
506 TargetGroupName: "{{ tg_name }}"
507 ip_address_type: dualstack
508 register: alb
509 check_mode: true
510 - ansible.builtin.assert:
511 that:
512 - alb is not changed
513 - alb.msg is match('IN CHECK MODE - no changes to make to ALB specified.')
514
515 - name: Create an ALB with ip address type (idempotence)
516 amazon.aws.elb_application_lb:
517 name: "{{ alb_name }}"
518 subnets: "{{ public_subnets }}"
519 security_groups: "{{ sec_group.group_id }}"
520 state: present
521 listeners:
522 - Protocol: HTTP
523 Port: 80
524 DefaultActions:
525 - Type: forward
526 TargetGroupName: "{{ tg_name }}"
527 ip_address_type: dualstack
528 register: alb
529 - ansible.builtin.assert:
530 that:
531 - alb is not changed
532 - alb.ip_address_type == 'dualstack'
533 - alb.routing_http2_enabled | bool
534 - alb.routing_http_desync_mitigation_mode == 'defensive'
535 - not alb.routing_http_drop_invalid_header_fields_enabled | bool
536 - not alb.routing_http_x_amzn_tls_version_and_cipher_suite_enabled | bool
537 - not alb.routing_http_xff_client_port_enabled | bool
538 - not alb.waf_fail_open_enabled | bool
539
540 # ------------------------------------------------------------------------------------------
541
542 - name: Update an ALB with different attributes - check_mode
543 amazon.aws.elb_application_lb:
544 name: "{{ alb_name }}"
545 subnets: "{{ public_subnets }}"
546 security_groups: "{{ sec_group.group_id }}"
547 state: present
548 listeners:
549 - Protocol: HTTP
550 Port: 80
551 DefaultActions:
552 - Type: forward
553 TargetGroupName: "{{ tg_name }}"
554 ip_address_type: dualstack
555 http2: false
556 http_desync_mitigation_mode: monitor
557 http_drop_invalid_header_fields: true
558 http_x_amzn_tls_version_and_cipher_suite: true
559 http_xff_client_port: true
560 waf_fail_open: true
561 register: alb
562 check_mode: true
563 - ansible.builtin.assert:
564 that:
565 - alb is changed
566 - alb.msg is match('Would have updated ALB if not in check mode.')
567
568 - name: Update an ALB with different attributes
569 amazon.aws.elb_application_lb:
570 name: "{{ alb_name }}"
571 subnets: "{{ public_subnets }}"
572 security_groups: "{{ sec_group.group_id }}"
573 state: present
574 listeners:
575 - Protocol: HTTP
576 Port: 80
577 DefaultActions:
578 - Type: forward
579 TargetGroupName: "{{ tg_name }}"
580 ip_address_type: dualstack
581 http2: false
582 http_desync_mitigation_mode: monitor
583 http_drop_invalid_header_fields: true
584 http_x_amzn_tls_version_and_cipher_suite: true
585 http_xff_client_port: true
586 waf_fail_open: true
587 register: alb
588 - ansible.builtin.assert:
589 that:
590 - alb is changed
591 - alb.ip_address_type == 'dualstack'
592 - not alb.routing_http2_enabled | bool
593 - alb.routing_http_desync_mitigation_mode == 'monitor'
594 - alb.routing_http_drop_invalid_header_fields_enabled | bool
595 - alb.routing_http_x_amzn_tls_version_and_cipher_suite_enabled | bool
596 - alb.routing_http_xff_client_port_enabled | bool
597 - alb.waf_fail_open_enabled | bool
598
599 - name: Update an ALB with different attributes (idempotence) - check_mode
600 amazon.aws.elb_application_lb:
601 name: "{{ alb_name }}"
602 subnets: "{{ public_subnets }}"
603 security_groups: "{{ sec_group.group_id }}"
604 state: present
605 listeners:
606 - Protocol: HTTP
607 Port: 80
608 DefaultActions:
609 - Type: forward
610 TargetGroupName: "{{ tg_name }}"
611 ip_address_type: dualstack
612 http2: false
613 http_desync_mitigation_mode: monitor
614 http_drop_invalid_header_fields: true
615 http_x_amzn_tls_version_and_cipher_suite: true
616 http_xff_client_port: true
617 waf_fail_open: true
618 register: alb
619 check_mode: true
620 - ansible.builtin.assert:
621 that:
622 - alb is not changed
623 - alb.msg is match('IN CHECK MODE - no changes to make to ALB specified.')
624
625 - name: Update an ALB with different attributes (idempotence)
626 amazon.aws.elb_application_lb:
627 name: "{{ alb_name }}"
628 subnets: "{{ public_subnets }}"
629 security_groups: "{{ sec_group.group_id }}"
630 state: present
631 listeners:
632 - Protocol: HTTP
633 Port: 80
634 DefaultActions:
635 - Type: forward
636 TargetGroupName: "{{ tg_name }}"
637 ip_address_type: dualstack
638 http2: false
639 http_desync_mitigation_mode: monitor
640 http_drop_invalid_header_fields: true
641 http_x_amzn_tls_version_and_cipher_suite: true
642 http_xff_client_port: true
643 waf_fail_open: true
644 register: alb
645 - ansible.builtin.assert:
646 that:
647 - alb is not changed
648 - alb.ip_address_type == 'dualstack'
649 - not alb.routing_http2_enabled | bool
650 - alb.routing_http_desync_mitigation_mode == 'monitor'
651 - alb.routing_http_drop_invalid_header_fields_enabled | bool
652 - alb.routing_http_x_amzn_tls_version_and_cipher_suite_enabled | bool
653 - alb.routing_http_xff_client_port_enabled | bool
654 - alb.waf_fail_open_enabled | bool
655
656 # ------------------------------------------------------------------------------------------
657
658 - name: Update an ALB with different ip address type - check_mode
659 amazon.aws.elb_application_lb:
660 name: "{{ alb_name }}"
661 subnets: "{{ public_subnets }}"
662 security_groups: "{{ sec_group.group_id }}"
663 state: present
664 listeners:
665 - Protocol: HTTP
666 Port: 80
667 DefaultActions:
668 - Type: forward
669 TargetGroupName: "{{ tg_name }}"
670 ip_address_type: ipv4
671 http2: false
672 http_desync_mitigation_mode: monitor
673 http_drop_invalid_header_fields: true
674 http_x_amzn_tls_version_and_cipher_suite: true
675 http_xff_client_port: true
676 waf_fail_open: true
677 register: alb
678 check_mode: true
679 - ansible.builtin.assert:
680 that:
681 - alb is changed
682 - alb.msg is match('Would have updated ALB if not in check mode.')
683
684 - name: Update an ALB with different ip address type
685 amazon.aws.elb_application_lb:
686 name: "{{ alb_name }}"
687 subnets: "{{ public_subnets }}"
688 security_groups: "{{ sec_group.group_id }}"
689 state: present
690 listeners:
691 - Protocol: HTTP
692 Port: 80
693 DefaultActions:
694 - Type: forward
695 TargetGroupName: "{{ tg_name }}"
696 ip_address_type: ipv4
697 http2: false
698 http_desync_mitigation_mode: monitor
699 http_drop_invalid_header_fields: true
700 http_x_amzn_tls_version_and_cipher_suite: true
701 http_xff_client_port: true
702 waf_fail_open: true
703 register: alb
704 - ansible.builtin.assert:
705 that:
706 - alb is changed
707 - alb.ip_address_type == 'ipv4'
708 - not alb.routing_http2_enabled | bool
709 - alb.routing_http_desync_mitigation_mode == 'monitor'
710 - alb.routing_http_drop_invalid_header_fields_enabled | bool
711 - alb.routing_http_x_amzn_tls_version_and_cipher_suite_enabled | bool
712 - alb.routing_http_xff_client_port_enabled | bool
713 - alb.waf_fail_open_enabled | bool
714
715 - name: Update an ALB with different ip address type (idempotence) - check_mode
716 amazon.aws.elb_application_lb:
717 name: "{{ alb_name }}"
718 subnets: "{{ public_subnets }}"
719 security_groups: "{{ sec_group.group_id }}"
720 state: present
721 listeners:
722 - Protocol: HTTP
723 Port: 80
724 DefaultActions:
725 - Type: forward
726 TargetGroupName: "{{ tg_name }}"
727 ip_address_type: ipv4
728 http2: false
729 http_desync_mitigation_mode: monitor
730 http_drop_invalid_header_fields: true
731 http_x_amzn_tls_version_and_cipher_suite: true
732 http_xff_client_port: true
733 waf_fail_open: true
734 register: alb
735 check_mode: true
736 - ansible.builtin.assert:
737 that:
738 - alb is not changed
739 - alb.msg is match('IN CHECK MODE - no changes to make to ALB specified.')
740
741 - name: Update an ALB with different ip address type (idempotence)
742 amazon.aws.elb_application_lb:
743 name: "{{ alb_name }}"
744 subnets: "{{ public_subnets }}"
745 security_groups: "{{ sec_group.group_id }}"
746 state: present
747 listeners:
748 - Protocol: HTTP
749 Port: 80
750 DefaultActions:
751 - Type: forward
752 TargetGroupName: "{{ tg_name }}"
753 ip_address_type: ipv4
754 http2: false
755 http_desync_mitigation_mode: monitor
756 http_drop_invalid_header_fields: true
757 http_x_amzn_tls_version_and_cipher_suite: true
758 http_xff_client_port: true
759 waf_fail_open: true
760 register: alb
761 - ansible.builtin.assert:
762 that:
763 - alb is not changed
764 - alb.ip_address_type == 'ipv4'
765 - not alb.routing_http2_enabled | bool
766 - alb.routing_http_desync_mitigation_mode == 'monitor'
767 - alb.routing_http_drop_invalid_header_fields_enabled | bool
768 - alb.routing_http_x_amzn_tls_version_and_cipher_suite_enabled | bool
769 - alb.routing_http_xff_client_port_enabled | bool
770 - alb.waf_fail_open_enabled | bool
771
772 # ------------------------------------------------------------------------------------------
773
774 - name: Update an ALB with different listener by adding rule - check_mode
775 amazon.aws.elb_application_lb:
776 name: "{{ alb_name }}"
777 subnets: "{{ public_subnets }}"
778 security_groups: "{{ sec_group.group_id }}"
779 state: present
780 listeners:
781 - Protocol: HTTP
782 Port: 80
783 DefaultActions:
784 - Type: forward
785 TargetGroupName: "{{ tg_name }}"
786 Rules:
787 - Conditions:
788 - Field: path-pattern
789 Values:
790 - /test
791 Priority: "1"
792 Actions:
793 - TargetGroupName: "{{ tg_name }}"
794 Type: forward
795 register: alb
796 check_mode: true
797 - ansible.builtin.assert:
798 that:
799 - alb is changed
800 - alb.msg is match('Would have updated ALB if not in check mode.')
801
802 - name: Update an ALB with different listener by adding rule
803 amazon.aws.elb_application_lb:
804 name: "{{ alb_name }}"
805 subnets: "{{ public_subnets }}"
806 security_groups: "{{ sec_group.group_id }}"
807 state: present
808 listeners:
809 - Protocol: HTTP
810 Port: 80
811 DefaultActions:
812 - Type: forward
813 TargetGroupName: "{{ tg_name }}"
814 Rules:
815 - Conditions:
816 - Field: path-pattern
817 Values:
818 - /test
819 Priority: "1"
820 Actions:
821 - TargetGroupName: "{{ tg_name }}"
822 Type: forward
823 register: alb
824 - ansible.builtin.assert:
825 that:
826 - alb is changed
827 - alb.listeners[0].rules | length == 2
828 - "'1' in alb.listeners[0].rules | map(attribute='priority')"
829
830 - name: Update an ALB with different listener by adding rule (idempotence) - check_mode
831 amazon.aws.elb_application_lb:
832 name: "{{ alb_name }}"
833 subnets: "{{ public_subnets }}"
834 security_groups: "{{ sec_group.group_id }}"
835 state: present
836 listeners:
837 - Protocol: HTTP
838 Port: 80
839 DefaultActions:
840 - Type: forward
841 TargetGroupName: "{{ tg_name }}"
842 Rules:
843 - Conditions:
844 - Field: path-pattern
845 Values:
846 - /test
847 Priority: "1"
848 Actions:
849 - TargetGroupName: "{{ tg_name }}"
850 Type: forward
851 register: alb
852 check_mode: true
853 - ansible.builtin.assert:
854 that:
855 - alb is not changed
856 - alb.msg is match('IN CHECK MODE - no changes to make to ALB specified.')
857
858 - name: Update an ALB with different listener by adding rule (idempotence)
859 amazon.aws.elb_application_lb:
860 name: "{{ alb_name }}"
861 subnets: "{{ public_subnets }}"
862 security_groups: "{{ sec_group.group_id }}"
863 state: present
864 listeners:
865 - Protocol: HTTP
866 Port: 80
867 DefaultActions:
868 - Type: forward
869 TargetGroupName: "{{ tg_name }}"
870 Rules:
871 - Conditions:
872 - Field: path-pattern
873 Values:
874 - /test
875 Priority: "1"
876 Actions:
877 - TargetGroupName: "{{ tg_name }}"
878 Type: forward
879 register: alb
880 - ansible.builtin.assert:
881 that:
882 - alb is not changed
883 - alb.listeners[0].rules | length == 2
884 - "'1' in alb.listeners[0].rules | map(attribute='priority')"
885
886 # ------------------------------------------------------------------------------------------
887
888 - name: Update an ALB with different listener by modifying rule - check_mode
889 amazon.aws.elb_application_lb:
890 name: "{{ alb_name }}"
891 subnets: "{{ public_subnets }}"
892 security_groups: "{{ sec_group.group_id }}"
893 state: present
894 listeners:
895 - Protocol: HTTP
896 Port: 80
897 DefaultActions:
898 - Type: forward
899 TargetGroupName: "{{ tg_name }}"
900 Rules:
901 - Conditions:
902 - Field: path-pattern
903 Values:
904 - /test
905 Priority: "2"
906 Actions:
907 - TargetGroupName: "{{ tg_name }}"
908 Type: forward
909 register: alb
910 check_mode: true
911 - ansible.builtin.assert:
912 that:
913 - alb is changed
914 - alb.msg is match('Would have updated ALB if not in check mode.')
915
916 - name: Update an ALB with different listener by modifying rule
917 amazon.aws.elb_application_lb:
918 name: "{{ alb_name }}"
919 subnets: "{{ public_subnets }}"
920 security_groups: "{{ sec_group.group_id }}"
921 state: present
922 listeners:
923 - Protocol: HTTP
924 Port: 80
925 DefaultActions:
926 - Type: forward
927 TargetGroupName: "{{ tg_name }}"
928 Rules:
929 - Conditions:
930 - Field: path-pattern
931 Values:
932 - /test
933 Priority: "2"
934 Actions:
935 - TargetGroupName: "{{ tg_name }}"
936 Type: forward
937 register: alb
938 - ansible.builtin.assert:
939 that:
940 - alb is changed
941 - alb.listeners[0].rules | length == 2
942 - "'2' in alb.listeners[0].rules | map(attribute='priority')"
943
944 - name: Update an ALB with different listener by modifying rule (idempotence) - check_mode
945 amazon.aws.elb_application_lb:
946 name: "{{ alb_name }}"
947 subnets: "{{ public_subnets }}"
948 security_groups: "{{ sec_group.group_id }}"
949 state: present
950 listeners:
951 - Protocol: HTTP
952 Port: 80
953 DefaultActions:
954 - Type: forward
955 TargetGroupName: "{{ tg_name }}"
956 Rules:
957 - Conditions:
958 - Field: path-pattern
959 Values:
960 - /test
961 Priority: "2"
962 Actions:
963 - TargetGroupName: "{{ tg_name }}"
964 Type: forward
965 register: alb
966 check_mode: true
967 - ansible.builtin.assert:
968 that:
969 - alb is not changed
970 - alb.msg is match('IN CHECK MODE - no changes to make to ALB specified.')
971
972 - name: Update an ALB with different listener by modifying rule (idempotence)
973 amazon.aws.elb_application_lb:
974 name: "{{ alb_name }}"
975 subnets: "{{ public_subnets }}"
976 security_groups: "{{ sec_group.group_id }}"
977 state: present
978 listeners:
979 - Protocol: HTTP
980 Port: 80
981 DefaultActions:
982 - Type: forward
983 TargetGroupName: "{{ tg_name }}"
984 Rules:
985 - Conditions:
986 - Field: path-pattern
987 Values:
988 - /test
989 Priority: "2"
990 Actions:
991 - TargetGroupName: "{{ tg_name }}"
992 Type: forward
993 register: alb
994 - ansible.builtin.assert:
995 that:
996 - alb is not changed
997 - alb.listeners[0].rules | length == 2
998 - "'2' in alb.listeners[0].rules | map(attribute='priority')"
999
1000 # ------------------------------------------------------------------------------------------
1001
1002 - name: Update an ALB with different listener by deleting rule - check_mode
1003 amazon.aws.elb_application_lb:
1004 name: "{{ alb_name }}"
1005 subnets: "{{ public_subnets }}"
1006 security_groups: "{{ sec_group.group_id }}"
1007 state: present
1008 listeners:
1009 - Protocol: HTTP
1010 Port: 80
1011 DefaultActions:
1012 - Type: forward
1013 TargetGroupName: "{{ tg_name }}"
1014 Rules: []
1015 register: alb
1016 check_mode: true
1017 - ansible.builtin.assert:
1018 that:
1019 - alb is changed
1020 - alb.msg is match('Would have updated ALB if not in check mode.')
1021
1022 - name: Update an ALB with different listener by deleting rule
1023 amazon.aws.elb_application_lb:
1024 name: "{{ alb_name }}"
1025 subnets: "{{ public_subnets }}"
1026 security_groups: "{{ sec_group.group_id }}"
1027 state: present
1028 listeners:
1029 - Protocol: HTTP
1030 Port: 80
1031 DefaultActions:
1032 - Type: forward
1033 TargetGroupName: "{{ tg_name }}"
1034 Rules: []
1035 register: alb
1036 - ansible.builtin.assert:
1037 that:
1038 - alb is changed
1039 - alb.listeners[0].rules | length == 1
1040 - "'2' not in alb.listeners[0].rules | map(attribute='priority')"
1041
1042 - name: Update an ALB with different listener by deleting rule (idempotence) - check_mode
1043 amazon.aws.elb_application_lb:
1044 name: "{{ alb_name }}"
1045 subnets: "{{ public_subnets }}"
1046 security_groups: "{{ sec_group.group_id }}"
1047 state: present
1048 listeners:
1049 - Protocol: HTTP
1050 Port: 80
1051 DefaultActions:
1052 - Type: forward
1053 TargetGroupName: "{{ tg_name }}"
1054 Rules: []
1055 register: alb
1056 check_mode: true
1057 - ansible.builtin.assert:
1058 that:
1059 - alb is not changed
1060 - alb.msg is match('IN CHECK MODE - no changes to make to ALB specified.')
1061
1062 - name: Update an ALB with different listener by deleting rule (idempotence)
1063 amazon.aws.elb_application_lb:
1064 name: "{{ alb_name }}"
1065 subnets: "{{ public_subnets }}"
1066 security_groups: "{{ sec_group.group_id }}"
1067 state: present
1068 listeners:
1069 - Protocol: HTTP
1070 Port: 80
1071 DefaultActions:
1072 - Type: forward
1073 TargetGroupName: "{{ tg_name }}"
1074 Rules: []
1075 register: alb
1076 - ansible.builtin.assert:
1077 that:
1078 - alb is not changed
1079 - alb.listeners[0].rules | length == 1
1080 - "'2' not in alb.listeners[0].rules | map(attribute='priority')"
1081
1082 # ------------------------------------------------------------------------------------------
1083
1084 - name: Update an ALB with different listener by modifying default actions - check mode
1085 amazon.aws.elb_application_lb:
1086 name: "{{ alb_name }}"
1087 subnets: "{{ public_subnets }}"
1088 security_groups: "{{ sec_group.group_id }}"
1089 state: present
1090 listeners:
1091 - Protocol: HTTP
1092 Port: 80
1093 DefaultActions:
1094 - Type: fixed-response
1095 FixedResponseConfig:
1096 ContentType: text/plain
1097 MessageBody: Not available
1098 StatusCode: "404"
1099 register: alb
1100 check_mode: true
1101
1102 - name: Assert check_mode result
1103 ansible.builtin.assert:
1104 that:
1105 - alb is changed
1106 - alb.msg is match('Would have updated ALB if not in check mode.')
1107
1108 - name: Update an ALB with different listener by modifying default actions
1109 amazon.aws.elb_application_lb:
1110 name: "{{ alb_name }}"
1111 subnets: "{{ public_subnets }}"
1112 security_groups: "{{ sec_group.group_id }}"
1113 state: present
1114 listeners:
1115 - Protocol: HTTP
1116 Port: 80
1117 DefaultActions:
1118 - Type: fixed-response
1119 FixedResponseConfig:
1120 ContentType: text/plain
1121 MessageBody: Not available
1122 StatusCode: "404"
1123 register: alb
1124
1125 - name: Assert update ALB result
1126 ansible.builtin.assert:
1127 that:
1128 - alb is changed
1129 - alb.listeners[0].default_actions[0].type == "fixed-response"
1130
1131 - name: Update an ALB with different listener by modifying default actions (idempotence) - check_mode
1132 amazon.aws.elb_application_lb:
1133 name: "{{ alb_name }}"
1134 subnets: "{{ public_subnets }}"
1135 security_groups: "{{ sec_group.group_id }}"
1136 state: present
1137 listeners:
1138 - Protocol: HTTP
1139 Port: 80
1140 DefaultActions:
1141 - Type: fixed-response
1142 FixedResponseConfig:
1143 ContentType: text/plain
1144 MessageBody: Not available
1145 StatusCode: "404"
1146 register: alb
1147 check_mode: true
1148
1149 - name: Assert check_mode idempotence result
1150 ansible.builtin.assert:
1151 that:
1152 - alb is not changed
1153 - alb.msg is match('IN CHECK MODE - no changes to make to ALB specified.')
1154
1155 - name: Update an ALB with different listener by modifying default actions (idempotence)
1156 amazon.aws.elb_application_lb:
1157 name: "{{ alb_name }}"
1158 subnets: "{{ public_subnets }}"
1159 security_groups: "{{ sec_group.group_id }}"
1160 state: present
1161 listeners:
1162 - Protocol: HTTP
1163 Port: 80
1164 DefaultActions:
1165 - Type: fixed-response
1166 FixedResponseConfig:
1167 ContentType: text/plain
1168 MessageBody: Not available
1169 StatusCode: "404"
1170 register: alb
1171
1172 - name: Assert idempotence result
1173 ansible.builtin.assert:
1174 that:
1175 - alb is not changed
1176 - alb.listeners[0].default_actions[0].type == "fixed-response"
1177
1178 # ------------------------------------------------------------------------------------------
1179
1180 - name: Update an ALB by deleting listener - check_mode
1181 amazon.aws.elb_application_lb:
1182 name: "{{ alb_name }}"
1183 subnets: "{{ public_subnets }}"
1184 security_groups: "{{ sec_group.group_id }}"
1185 state: present
1186 listeners: []
1187 register: alb
1188 check_mode: true
1189 - ansible.builtin.assert:
1190 that:
1191 - alb is changed
1192 - alb.msg is match('Would have updated ALB if not in check mode.')
1193
1194 - name: Update an ALB by deleting listener
1195 amazon.aws.elb_application_lb:
1196 name: "{{ alb_name }}"
1197 subnets: "{{ public_subnets }}"
1198 security_groups: "{{ sec_group.group_id }}"
1199 state: present
1200 listeners: []
1201 register: alb
1202 - ansible.builtin.assert:
1203 that:
1204 - alb is changed
1205 - not alb.listeners
1206
1207 - name: Update an ALB by deleting listener (idempotence) - check_mode
1208 amazon.aws.elb_application_lb:
1209 name: "{{ alb_name }}"
1210 subnets: "{{ public_subnets }}"
1211 security_groups: "{{ sec_group.group_id }}"
1212 state: present
1213 listeners: []
1214 register: alb
1215 check_mode: true
1216 - ansible.builtin.assert:
1217 that:
1218 - alb is not changed
1219 - alb.msg is match('IN CHECK MODE - no changes to make to ALB specified.')
1220
1221 - name: Update an ALB by deleting listener (idempotence)
1222 amazon.aws.elb_application_lb:
1223 name: "{{ alb_name }}"
1224 subnets: "{{ public_subnets }}"
1225 security_groups: "{{ sec_group.group_id }}"
1226 state: present
1227 listeners: []
1228 register: alb
1229 - ansible.builtin.assert:
1230 that:
1231 - alb is not changed
1232 - not alb.listeners
1233
1234 # ------------------------------------------------------------------------------------------
1235
1236 - name: Update an ALB by adding tags - check_mode
1237 amazon.aws.elb_application_lb:
1238 name: "{{ alb_name }}"
1239 subnets: "{{ public_subnets }}"
1240 security_groups: "{{ sec_group.group_id }}"
1241 state: present
1242 tags:
1243 created_by: ALB test {{ resource_prefix }}
1244 register: alb
1245 check_mode: true
1246 - ansible.builtin.assert:
1247 that:
1248 - alb is changed
1249 - alb.msg is match('Would have updated ALB if not in check mode.')
1250
1251 - name: Update an ALB by adding tags
1252 amazon.aws.elb_application_lb:
1253 name: "{{ alb_name }}"
1254 subnets: "{{ public_subnets }}"
1255 security_groups: "{{ sec_group.group_id }}"
1256 state: present
1257 tags:
1258 created_by: ALB test {{ resource_prefix }}
1259 register: alb
1260 - ansible.builtin.assert:
1261 that:
1262 - alb is changed
1263 - alb.tags == created_tags
1264 vars:
1265 created_tags:
1266 created_by: ALB test {{ resource_prefix }}
1267
1268 - name: Update an ALB by adding tags (idempotence) - check_mode
1269 amazon.aws.elb_application_lb:
1270 name: "{{ alb_name }}"
1271 subnets: "{{ public_subnets }}"
1272 security_groups: "{{ sec_group.group_id }}"
1273 state: present
1274 tags:
1275 created_by: ALB test {{ resource_prefix }}
1276 register: alb
1277 check_mode: true
1278 - ansible.builtin.assert:
1279 that:
1280 - alb is not changed
1281 - alb.msg is match('IN CHECK MODE - no changes to make to ALB specified.')
1282
1283 - name: Update an ALB by adding tags (idempotence)
1284 amazon.aws.elb_application_lb:
1285 name: "{{ alb_name }}"
1286 subnets: "{{ public_subnets }}"
1287 security_groups: "{{ sec_group.group_id }}"
1288 state: present
1289 tags:
1290 created_by: ALB test {{ resource_prefix }}
1291 register: alb
1292 - ansible.builtin.assert:
1293 that:
1294 - alb is not changed
1295 - alb.tags == created_tags
1296 vars:
1297 created_tags:
1298 created_by: ALB test {{ resource_prefix }}
1299
1300 # ------------------------------------------------------------------------------------------
1301
1302 - name: Update an ALB by modifying tags - check_mode
1303 amazon.aws.elb_application_lb:
1304 name: "{{ alb_name }}"
1305 subnets: "{{ public_subnets }}"
1306 security_groups: "{{ sec_group.group_id }}"
1307 state: present
1308 tags:
1309 created_by: ALB test {{ resource_prefix }}-2
1310 register: alb
1311 check_mode: true
1312 - ansible.builtin.assert:
1313 that:
1314 - alb is changed
1315 - alb.msg is match('Would have updated ALB if not in check mode.')
1316
1317 - name: Update an ALB by modifying tags
1318 amazon.aws.elb_application_lb:
1319 name: "{{ alb_name }}"
1320 subnets: "{{ public_subnets }}"
1321 security_groups: "{{ sec_group.group_id }}"
1322 state: present
1323 tags:
1324 created_by: ALB test {{ resource_prefix }}-2
1325 register: alb
1326 - ansible.builtin.assert:
1327 that:
1328 - alb is changed
1329 - alb.tags == created_tags
1330 vars:
1331 created_tags:
1332 created_by: ALB test {{ resource_prefix }}-2
1333
1334 - name: Update an ALB by modifying tags (idempotence) - check_mode
1335 amazon.aws.elb_application_lb:
1336 name: "{{ alb_name }}"
1337 subnets: "{{ public_subnets }}"
1338 security_groups: "{{ sec_group.group_id }}"
1339 state: present
1340 tags:
1341 created_by: ALB test {{ resource_prefix }}-2
1342 register: alb
1343 check_mode: true
1344 - ansible.builtin.assert:
1345 that:
1346 - alb is not changed
1347 - alb.msg is match('IN CHECK MODE - no changes to make to ALB specified.')
1348
1349 - name: Update an ALB by modifying tags (idempotence)
1350 amazon.aws.elb_application_lb:
1351 name: "{{ alb_name }}"
1352 subnets: "{{ public_subnets }}"
1353 security_groups: "{{ sec_group.group_id }}"
1354 state: present
1355 tags:
1356 created_by: ALB test {{ resource_prefix }}-2
1357 register: alb
1358 - ansible.builtin.assert:
1359 that:
1360 - alb is not changed
1361 - alb.tags == created_tags
1362 vars:
1363 created_tags:
1364 created_by: ALB test {{ resource_prefix }}-2
1365
1366 # ------------------------------------------------------------------------------------------
1367
1368 - name: Update an ALB by removing tags - check_mode
1369 amazon.aws.elb_application_lb:
1370 name: "{{ alb_name }}"
1371 subnets: "{{ public_subnets }}"
1372 security_groups: "{{ sec_group.group_id }}"
1373 state: present
1374 tags: {}
1375 register: alb
1376 check_mode: true
1377 - ansible.builtin.assert:
1378 that:
1379 - alb is changed
1380 - alb.msg is match('Would have updated ALB if not in check mode.')
1381
1382 - name: Update an ALB by removing tags
1383 amazon.aws.elb_application_lb:
1384 name: "{{ alb_name }}"
1385 subnets: "{{ public_subnets }}"
1386 security_groups: "{{ sec_group.group_id }}"
1387 state: present
1388 tags: {}
1389 register: alb
1390 - ansible.builtin.assert:
1391 that:
1392 - alb is changed
1393 - not alb.tags
1394
1395 - name: Update an ALB by removing tags (idempotence) - check_mode
1396 amazon.aws.elb_application_lb:
1397 name: "{{ alb_name }}"
1398 subnets: "{{ public_subnets }}"
1399 security_groups: "{{ sec_group.group_id }}"
1400 state: present
1401 tags: {}
1402 register: alb
1403 check_mode: true
1404 - ansible.builtin.assert:
1405 that:
1406 - alb is not changed
1407 - alb.msg is match('IN CHECK MODE - no changes to make to ALB specified.')
1408
1409 - name: Update an ALB by removing tags (idempotence)
1410 amazon.aws.elb_application_lb:
1411 name: "{{ alb_name }}"
1412 subnets: "{{ public_subnets }}"
1413 security_groups: "{{ sec_group.group_id }}"
1414 state: present
1415 tags: {}
1416 register: alb
1417 - ansible.builtin.assert:
1418 that:
1419 - alb is not changed
1420 - not alb.tags
1421
1422 # ------------------------------------------------------------------------------------------
1423
1424 - name: Update an ALB by changing security group - check_mode
1425 amazon.aws.elb_application_lb:
1426 name: "{{ alb_name }}"
1427 subnets: "{{ public_subnets }}"
1428 security_groups: "{{ sec_group2.group_id }}"
1429 state: present
1430 register: alb
1431 check_mode: true
1432 - ansible.builtin.assert:
1433 that:
1434 - alb is changed
1435 - alb.msg is match('Would have updated ALB if not in check mode.')
1436
1437 - name: Update an ALB by changing security group
1438 amazon.aws.elb_application_lb:
1439 name: "{{ alb_name }}"
1440 subnets: "{{ public_subnets }}"
1441 security_groups: "{{ sec_group2.group_id }}"
1442 state: present
1443 register: alb
1444 - ansible.builtin.assert:
1445 that:
1446 - alb is changed
1447 - alb.security_groups[0] == sec_group2.group_id
1448
1449 - name: Update an ALB by changing security group (idempotence) - check_mode
1450 amazon.aws.elb_application_lb:
1451 name: "{{ alb_name }}"
1452 subnets: "{{ public_subnets }}"
1453 security_groups: "{{ sec_group2.group_id }}"
1454 state: present
1455 register: alb
1456 check_mode: true
1457 - ansible.builtin.assert:
1458 that:
1459 - alb is not changed
1460 - alb.msg is match('IN CHECK MODE - no changes to make to ALB specified.')
1461
1462 - name: Update an ALB by changing security group (idempotence)
1463 amazon.aws.elb_application_lb:
1464 name: "{{ alb_name }}"
1465 subnets: "{{ public_subnets }}"
1466 security_groups: "{{ sec_group2.group_id }}"
1467 state: present
1468 register: alb
1469 - ansible.builtin.assert:
1470 that:
1471 - alb is not changed
1472 - alb.security_groups[0] == sec_group2.group_id
1473
1474 # ------------------------------------------------------------------------------------------
1475
1476 - name: Ensure elb_application_lb_info supports check_mode
1477 amazon.aws.elb_application_lb_info:
1478 register: alb_info
1479 check_mode: true
1480 - ansible.builtin.assert:
1481 that:
1482 - alb_info.load_balancers | length > 0
1483
1484 - name: Get ALB application info using no args
1485 amazon.aws.elb_application_lb_info:
1486 register: alb_info
1487 - ansible.builtin.assert:
1488 that:
1489 - alb_info.load_balancers | length > 0
1490
1491 - name: Get ALB application info using load balancer arn
1492 amazon.aws.elb_application_lb_info:
1493 load_balancer_arns:
1494 - "{{ alb.load_balancer_arn }}"
1495 register: alb_info
1496 - ansible.builtin.assert:
1497 that:
1498 - alb_info.load_balancers[0].security_groups[0] == sec_group2.group_id
1499
1500 - name: Get ALB application info using load balancer name
1501 amazon.aws.elb_application_lb_info:
1502 names:
1503 - "{{ alb.load_balancer_name }}"
1504 register: alb_info
1505 - ansible.builtin.assert:
1506 that:
1507 - alb_info.load_balancers[0].security_groups[0] == sec_group2.group_id
1508
1509 - name: Get ALB application info without skipping anything
1510 amazon.aws.elb_application_lb_info:
1511 names:
1512 - "{{ alb_2_name }}"
1513 register: alb_info
1514 - ansible.builtin.assert:
1515 that:
1516 - alb_info.load_balancers | selectattr('access_logs_s3_bucket', 'defined') | length > 0
1517 - alb_info.load_balancers | selectattr('access_logs_s3_enabled', 'defined') | length > 0
1518 - alb_info.load_balancers | selectattr('access_logs_s3_prefix', 'defined') | length > 0
1519 - alb_info.load_balancers | selectattr('deletion_protection_enabled', 'defined') | length > 0
1520 - alb_info.load_balancers | selectattr('idle_timeout_timeout_seconds', 'defined') | length > 0
1521 - alb_info.load_balancers | selectattr('load_balancing_cross_zone_enabled', 'defined') | length > 0
1522 - alb_info.load_balancers | selectattr('routing_http2_enabled', 'defined') | length > 0
1523 - alb_info.load_balancers | selectattr('routing_http_desync_mitigation_mode', 'defined') | length > 0
1524 - alb_info.load_balancers | selectattr('routing_http_drop_invalid_header_fields_enabled', 'defined') | length > 0
1525 - alb_info.load_balancers | selectattr('routing_http_x_amzn_tls_version_and_cipher_suite_enabled', 'defined') | length > 0
1526 - alb_info.load_balancers | selectattr('routing_http_xff_client_port_enabled', 'defined') | length > 0
1527 - alb_info.load_balancers | selectattr('waf_fail_open_enabled', 'defined') | length > 0
1528 - alb_info.load_balancers | selectattr('listeners', 'defined') | length > 0
1529 - alb_info.load_balancers | map(attribute='listeners') | flatten | selectattr('rules', 'defined') | length > 0
1530
1531 - name: Get ALB application info excluding attributes
1532 amazon.aws.elb_application_lb_info:
1533 names:
1534 - "{{ alb_2_name }}"
1535 include_attributes: false
1536 register: alb_info
1537 - ansible.builtin.assert:
1538 that:
1539 - alb_info.load_balancers | selectattr('access_logs_s3_bucket', 'defined') | length == 0
1540 - alb_info.load_balancers | selectattr('access_logs_s3_enabled', 'defined') | length == 0
1541 - alb_info.load_balancers | selectattr('access_logs_s3_prefix', 'defined') | length == 0
1542 - alb_info.load_balancers | selectattr('deletion_protection_enabled', 'defined') | length == 0
1543 - alb_info.load_balancers | selectattr('idle_timeout_timeout_seconds', 'defined') | length == 0
1544 - alb_info.load_balancers | selectattr('load_balancing_cross_zone_enabled', 'defined') | length == 0
1545 - alb_info.load_balancers | selectattr('routing_http2_enabled', 'defined') | length == 0
1546 - alb_info.load_balancers | selectattr('routing_http_desync_mitigation_mode', 'defined') | length == 0
1547 - alb_info.load_balancers | selectattr('routing_http_drop_invalid_header_fields_enabled', 'defined') | length == 0
1548 - alb_info.load_balancers | selectattr('routing_http_x_amzn_tls_version_and_cipher_suite_enabled', 'defined') | length == 0
1549 - alb_info.load_balancers | selectattr('routing_http_xff_client_port_enabled', 'defined') | length == 0
1550 - alb_info.load_balancers | selectattr('waf_fail_open_enabled', 'defined') | length == 0
1551
1552 - name: Get ALB application info without listeners, but with rules
1553 amazon.aws.elb_application_lb_info:
1554 names:
1555 - "{{ alb_2_name }}"
1556 include_listeners: false
1557 register: alb_info
1558 - ansible.builtin.assert:
1559 that:
1560 - alb_info.load_balancers | selectattr('listeners', 'defined') | length > 0
1561 - alb_info.load_balancers[0].listeners | length > 0
1562
1563 - name: Get ALB application info without listeners or rules
1564 amazon.aws.elb_application_lb_info:
1565 names:
1566 - "{{ alb_2_name }}"
1567 include_listeners: false
1568 include_listener_rules: false
1569 register: alb_info
1570 - ansible.builtin.assert:
1571 that:
1572 - alb_info.load_balancers | selectattr('listeners', 'defined') | length == 0
1573
1574 - name: Get ALB application info without listener rules
1575 amazon.aws.elb_application_lb_info:
1576 names:
1577 - "{{ alb_2_name }}"
1578 include_listener_rules: false
1579 register: alb_info
1580 - ansible.builtin.assert:
1581 that:
1582 - alb_info.load_balancers | selectattr('listeners', 'defined') | length > 0
1583 - alb_info.load_balancers | map(attribute='listeners') | flatten | selectattr('rules', 'defined') | length == 0
1584
1585 - name: Get ALB application minimal info
1586 amazon.aws.elb_application_lb_info:
1587 names:
1588 - "{{ alb_2_name }}"
1589 include_attributes: false
1590 include_listeners: false
1591 include_listener_rules: false
1592 register: alb_info
1593 - ansible.builtin.assert:
1594 that:
1595 - alb_info.load_balancers | selectattr('access_logs_s3_bucket', 'defined') | length == 0
1596 - alb_info.load_balancers | selectattr('access_logs_s3_enabled', 'defined') | length == 0
1597 - alb_info.load_balancers | selectattr('access_logs_s3_prefix', 'defined') | length == 0
1598 - alb_info.load_balancers | selectattr('deletion_protection_enabled', 'defined') | length == 0
1599 - alb_info.load_balancers | selectattr('idle_timeout_timeout_seconds', 'defined') | length == 0
1600 - alb_info.load_balancers | selectattr('load_balancing_cross_zone_enabled', 'defined') | length == 0
1601 - alb_info.load_balancers | selectattr('routing_http2_enabled', 'defined') | length == 0
1602 - alb_info.load_balancers | selectattr('routing_http_desync_mitigation_mode', 'defined') | length == 0
1603 - alb_info.load_balancers | selectattr('routing_http_drop_invalid_header_fields_enabled', 'defined') | length == 0
1604 - alb_info.load_balancers | selectattr('routing_http_x_amzn_tls_version_and_cipher_suite_enabled', 'defined') | length == 0
1605 - alb_info.load_balancers | selectattr('routing_http_xff_client_port_enabled', 'defined') | length == 0
1606 - alb_info.load_balancers | selectattr('waf_fail_open_enabled', 'defined') | length == 0
1607 - alb_info.load_balancers | selectattr('listeners', 'defined') | length == 0
1608
1609 # ------------------------------------------------------------------------------------------
1610
1611 - name: Delete an ALB - check_mode
1612 amazon.aws.elb_application_lb:
1613 name: "{{ alb_name }}"
1614 state: absent
1615 register: alb
1616 check_mode: true
1617 - ansible.builtin.assert:
1618 that:
1619 - alb is changed
1620 - alb.msg is match('Would have deleted ALB if not in check mode.')
1621
1622 - name: Delete an ALB
1623 amazon.aws.elb_application_lb:
1624 name: "{{ alb_name }}"
1625 state: absent
1626 register: alb
1627 - ansible.builtin.assert:
1628 that:
1629 - alb is changed
1630
1631 - name: Delete an ALB (idempotence) - check_mode
1632 amazon.aws.elb_application_lb:
1633 name: "{{ alb_name }}"
1634 state: absent
1635 register: alb
1636 check_mode: true
1637 - ansible.builtin.assert:
1638 that:
1639 - alb is not changed
1640 - alb.msg is match('IN CHECK MODE - ALB already absent.')
1641
1642 - name: Delete an ALB (idempotence)
1643 amazon.aws.elb_application_lb:
1644 name: "{{ alb_name }}"
1645 state: absent
1646 register: alb
1647 - ansible.builtin.assert:
1648 that:
1649 - alb is not changed
1650
1651 # ----- Cleanup ------------------------------------------------------------------------------
1652
1653 always:
1654 - name: Destroy ALB
1655 amazon.aws.elb_application_lb:
1656 name: "{{ alb_name }}"
1657 state: absent
1658 wait: true
1659 wait_timeout: 600
1660 ignore_errors: true # noqa: ignore-errors
1661 - name: Destroy ALB 2
1662 amazon.aws.elb_application_lb:
1663 name: "{{ alb_2_name }}"
1664 state: absent
1665 wait: true
1666 wait_timeout: 600
1667 ignore_errors: true # noqa: ignore-errors
1668 - name: Destroy target group if it was created
1669 community.aws.elb_target_group:
1670 name: "{{ tg_name }}"
1671 protocol: http
1672 port: 80
1673 vpc_id: "{{ vpc_id }}"
1674 state: absent
1675 wait: true
1676 wait_timeout: 600
1677 register: remove_tg
1678 retries: 5
1679 delay: 3
1680 until: remove_tg is success
1681 when: tg is defined
1682 ignore_errors: true # noqa: ignore-errors
1683 - name: Destroy target group 2 if it was created
1684 community.aws.elb_target_group:
1685 name: "{{ tg_2_name }}"
1686 protocol: http
1687 port: 80
1688 vpc_id: "{{ vpc_id }}"
1689 state: absent
1690 wait: true
1691 wait_timeout: 600
1692 register: remove_tg_2
1693 retries: 5
1694 delay: 3
1695 until: remove_tg_2 is success
1696 when: tg_2 is defined
1697 ignore_errors: true # noqa: ignore-errors
1698 - name: Destroy sec groups
1699 amazon.aws.ec2_security_group:
1700 name: "{{ item }}"
1701 description: security group for Ansible ALB integration tests
1702 state: absent
1703 vpc_id: "{{ vpc_id }}"
1704 register: remove_sg
1705 retries: 10
1706 delay: 5
1707 until: remove_sg is success
1708 ignore_errors: true # noqa: ignore-errors
1709 with_items:
1710 - "{{ resource_prefix }}"
1711 - "{{ resource_prefix }}-2"
1712
1713 - name: Destroy route table
1714 amazon.aws.ec2_vpc_route_table:
1715 vpc_id: "{{ vpc_id }}"
1716 route_table_id: "{{ route_table.route_table.route_table_id }}"
1717 lookup: id
1718 state: absent
1719 register: remove_rt
1720 retries: 10
1721 delay: 5
1722 until: remove_rt is success
1723 ignore_errors: true # noqa: ignore-errors
1724 - name: Destroy subnets
1725 amazon.aws.ec2_vpc_subnet:
1726 cidr: "{{ item }}"
1727 vpc_id: "{{ vpc_id }}"
1728 state: absent
1729 register: remove_subnet
1730 retries: 10
1731 delay: 5
1732 until: remove_subnet is success
1733 with_items:
1734 - "{{ private_subnet_cidr_1 }}"
1735 - "{{ private_subnet_cidr_2 }}"
1736 - "{{ public_subnet_cidr_1 }}"
1737 - "{{ public_subnet_cidr_2 }}"
1738 ignore_errors: true # noqa: ignore-errors
1739 - name: Destroy internet gateway
1740 amazon.aws.ec2_vpc_igw:
1741 vpc_id: "{{ vpc_id }}"
1742 tags:
1743 Name: "{{ resource_prefix }}"
1744 state: absent
1745 register: remove_igw
1746 retries: 10
1747 delay: 5
1748 until: remove_igw is success
1749 ignore_errors: true # noqa: ignore-errors
1750 - name: Destroy VPC
1751 amazon.aws.ec2_vpc_net:
1752 cidr_block: "{{ vpc_cidr }}"
1753 name: "{{ resource_prefix }}_vpc"
1754 state: absent
1755 register: remove_vpc
1756 retries: 10
1757 delay: 5
1758 until: remove_vpc is success
1759 ignore_errors: true # noqa: ignore-errors
1760 - name: Destroy ELB acccess log test file
1761 amazon.aws.s3_object:
1762 bucket: "{{ s3_bucket_name }}"
1763 mode: delobj
1764 object: alb-logs/AWSLogs/{{ aws_account }}/ELBAccessLogTestFile
1765 - name: Destroy S3 bucket
1766 amazon.aws.s3_bucket:
1767 name: "{{ s3_bucket_name }}"
1768 state: absent
1769 force: true