[2.9] various elbv2 bugfixes (#65212)

* Add aws elb multiple host header support (#65021)

* Add support for aws elbv2 multiple host header actions

* Add example of multiple host header

* Add test for multiple host headers

* Add missing quote

* Update test/integration/targets/elb_application_lb/tasks/test_modifying_alb_listeners.yml

Co-Authored-By: Jill R <4121322+jillr@users.noreply.github.com>

* Update test/integration/targets/elb_application_lb/tasks/test_modifying_alb_listeners.yml

Co-Authored-By: Jill R <4121322+jillr@users.noreply.github.com>

* Remove debug statements

(cherry picked from commit d52af75c68)

* elbv2 - print() statement results an task failure, even if the task itself was successfull (#65183)

(cherry picked from commit cba9abcbec)

* Add changelog fragment.

* Update changelogs/fragments/65021-65183-elb-bugs.yml

* Force values to be sorted when compared. (#65315)

* Force values to be sorted when compared.

This avoids problems where lists of values could be generated in
indeterminate order.

* Update lib/ansible/module_utils/aws/elbv2.py

Thank you felixfontein, sorry I missed this detail.

Co-Authored-By: Felix Fontein <felix@fontein.de>
(cherry picked from commit 777b6d3e30)

* Update changelog.

Co-authored-by: Michael Mayer <mjmayer@gmail.com>
Co-authored-by: Markus Bergholz <markuman@gmail.com>
Co-authored-by: roberbri <roberbri@cisco.com>
pull/66383/head
Felix Fontein 6 years ago committed by Matt Clay
parent a7bb6700c6
commit b55f20a3ee

@ -0,0 +1,3 @@
bugfixes:
- "elb_application_lb, elb_network_lb - fixed errors during listener rule comparison which caused broken JSON, and which caused some values not being compared correctly. (https://github.com/ansible/ansible/issues/65020)"
- "elb_application_lb, elb_network_lb - idempotence check for rules now compares all values order-independently, instead of just comparing the first value if multiple are specified."

@ -717,7 +717,7 @@ class ELBListenerRules(object):
current_condition['SourceIpConfig']['Values'][0] == condition['SourceIpConfig']['Values'][0]): current_condition['SourceIpConfig']['Values'][0] == condition['SourceIpConfig']['Values'][0]):
condition_found = True condition_found = True
break break
elif current_condition['Field'] == condition['Field'] and current_condition['Values'][0] == condition['Values'][0]: elif current_condition['Field'] == condition['Field'] and sorted(current_condition['Values']) == sorted(condition['Values']):
condition_found = True condition_found = True
break break
@ -732,7 +732,7 @@ class ELBListenerRules(object):
modified_rule = {} modified_rule = {}
# Priority # Priority
if int(current_rule['Priority']) != new_rule['Priority']: if int(current_rule['Priority']) != int(new_rule['Priority']):
modified_rule['Priority'] = new_rule['Priority'] modified_rule['Priority'] = new_rule['Priority']
# Actions # Actions
@ -754,8 +754,6 @@ class ELBListenerRules(object):
if len(current_rule['Actions']) == 1 and len(new_rule['Actions']) == 1: if len(current_rule['Actions']) == 1 and len(new_rule['Actions']) == 1:
if current_rule['Actions'] != new_rule['Actions']: if current_rule['Actions'] != new_rule['Actions']:
modified_rule['Actions'] = new_rule['Actions'] modified_rule['Actions'] = new_rule['Actions']
print("modified_rule:")
print(new_rule['Actions'])
# if actions have multiple elements, we'll have to order them first before comparing. # if actions have multiple elements, we'll have to order them first before comparing.
# multiple actions will have an 'Order' key for this purpose # multiple actions will have an 'Order' key for this purpose
else: else:
@ -776,13 +774,9 @@ class ELBListenerRules(object):
if current_actions_sorted != new_actions_sorted_no_secret: if current_actions_sorted != new_actions_sorted_no_secret:
modified_rule['Actions'] = new_rule['Actions'] modified_rule['Actions'] = new_rule['Actions']
print("modified_rule:")
print(new_rule['Actions'])
# If the action lengths are different, then replace with the new actions # If the action lengths are different, then replace with the new actions
else: else:
modified_rule['Actions'] = new_rule['Actions'] modified_rule['Actions'] = new_rule['Actions']
print("modified_rule:")
print(new_rule['Actions'])
# Conditions # Conditions
modified_conditions = [] modified_conditions = []

@ -237,6 +237,15 @@ EXAMPLES = '''
ContentType: "text/plain" ContentType: "text/plain"
MessageBody: "This is the page you're looking for" MessageBody: "This is the page you're looking for"
StatusCode: "200" StatusCode: "200"
- Conditions:
- Field: host-header
Values:
- "hostname.domain.com"
- "alternate.domain.com"
Priority: '4'
Actions:
- TargetGroupName: test-target-group
Type: forward
state: present state: present
# Remove an ELB # Remove an ELB

@ -118,6 +118,69 @@
- alb.changed - alb.changed
- alb.listeners[0].rules|length == 3 - alb.listeners[0].rules|length == 3
- name: add a rule that uses the host header condition to the listener
elb_application_lb:
name: "{{ alb_name }}"
subnets: "{{ alb_subnets }}"
security_groups: "{{ sec_group.group_id }}"
state: present
purge_rules: no
listeners:
- Protocol: HTTP
Port: 80
DefaultActions:
- Type: forward
TargetGroupName: "{{ tg_name }}"
Rules:
- Conditions:
- Field: host-header
Values:
- 'local.mydomain.com'
Priority: '3'
Actions:
- TargetGroupName: "{{ tg_name }}"
Type: forward
<<: *aws_connection_info
register: alb
- assert:
that:
- alb.changed
- alb.listeners[0].rules|length == 4
- '{{ alb|json_query("listeners[].rules[].conditions[].host_header_config.values[]")|length == 1 }}'
- name: test replacing the rule that uses the host header condition with multiple host header conditions
elb_application_lb:
name: "{{ alb_name }}"
subnets: "{{ alb_subnets }}"
security_groups: "{{ sec_group.group_id }}"
purge_rules: no
state: present
listeners:
- Protocol: HTTP
Port: 80
DefaultActions:
- Type: forward
TargetGroupName: "{{ tg_name }}"
Rules:
- Conditions:
- Field: host-header
Values:
- 'local.mydomain.com'
- 'alternate.mydomain.com'
Priority: '3'
Actions:
- TargetGroupName: "{{ tg_name }}"
Type: forward
<<: *aws_connection_info
register: alb
- assert:
that:
- alb.changed
- alb.listeners[0].rules|length == 4
- '{{ alb|json_query("listeners[].rules[].conditions[].host_header_config.values[]")|length == 2 }}'
- name: remove the rule - name: remove the rule
elb_application_lb: elb_application_lb:
name: "{{ alb_name }}" name: "{{ alb_name }}"

Loading…
Cancel
Save