[cloud] Only get rules if listener in elb_application_lb been identified in compare_rules (#30604)

* Only get rules if listener has been identified in compare_rules

* Always cast the listener port to an integer.

(cherry picked from commit 7cdaa3089ed2053f6fcfcea524a0322f40a2a822)
This commit is contained in:
Rob 2017-10-03 07:57:41 +11:00 committed by Ryan S. Brown
parent 25eb9154e9
commit 19c6fe9a78

View file

@ -615,6 +615,8 @@ def compare_listeners(connection, module, current_listeners, new_listeners, purg
Compare listeners and return listeners to add, listeners to modify and listeners to remove Compare listeners and return listeners to add, listeners to modify and listeners to remove
Listeners are compared based on port Listeners are compared based on port
:param connection: ELBv2 boto3 connection
:param module: Ansible module object
:param current_listeners: :param current_listeners:
:param new_listeners: :param new_listeners:
:param purge_listeners: :param purge_listeners:
@ -655,10 +657,10 @@ def compare_rules(connection, module, current_listeners, listener):
Compare rules and return rules to add, rules to modify and rules to remove Compare rules and return rules to add, rules to modify and rules to remove
Rules are compared based on priority Rules are compared based on priority
:param connection: :param connection: ELBv2 boto3 connection
:param module: :param module: Ansible module object
:param current_listeners: :param current_listeners: list of listeners currently associated with the ELB
:param listener: :param listener: dict object of a listener passed by the user
:return: :return:
""" """
@ -668,8 +670,11 @@ def compare_rules(connection, module, current_listeners, listener):
listener['ListenerArn'] = current_listener['ListenerArn'] listener['ListenerArn'] = current_listener['ListenerArn']
break break
# Get rules for the listener # If the listener exists (i.e. has an ARN) get rules for the listener
if 'ListenerArn' in listener:
current_rules = get_listener_rules(connection, module, listener['ListenerArn']) current_rules = get_listener_rules(connection, module, listener['ListenerArn'])
else:
current_rules = []
rules_to_modify = [] rules_to_modify = []
rules_to_delete = [] rules_to_delete = []
@ -993,6 +998,9 @@ def main():
if key not in ['Protocol', 'Port', 'SslPolicy', 'Certificates', 'DefaultActions', 'Rules']: if key not in ['Protocol', 'Port', 'SslPolicy', 'Certificates', 'DefaultActions', 'Rules']:
module.fail_json(msg="listeners parameter contains invalid dict keys. Should be one of 'Protocol', " module.fail_json(msg="listeners parameter contains invalid dict keys. Should be one of 'Protocol', "
"'Port', 'SslPolicy', 'Certificates', 'DefaultActions', 'Rules'.") "'Port', 'SslPolicy', 'Certificates', 'DefaultActions', 'Rules'.")
# Make sure Port is always an integer
elif key == 'Port':
listener[key] = int(listener[key])
if not HAS_BOTO3: if not HAS_BOTO3:
module.fail_json(msg='boto3 required for this module') module.fail_json(msg='boto3 required for this module')