[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.
pull/31184/head
Rob 7 years ago committed by Ryan Brown
parent 46fd083138
commit 2804a2663a

@ -619,6 +619,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:
@ -659,10 +661,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:
""" """
@ -672,8 +674,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
current_rules = get_listener_rules(connection, module, listener['ListenerArn']) if 'ListenerArn' in listener:
current_rules = get_listener_rules(connection, module, listener['ListenerArn'])
else:
current_rules = []
rules_to_modify = [] rules_to_modify = []
rules_to_delete = [] rules_to_delete = []
@ -997,6 +1002,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')

Loading…
Cancel
Save