diff --git a/lib/ansible/modules/cloud/amazon/elb_application_lb.py b/lib/ansible/modules/cloud/amazon/elb_application_lb.py index e5cdcac220..e426dde7ba 100644 --- a/lib/ansible/modules/cloud/amazon/elb_application_lb.py +++ b/lib/ansible/modules/cloud/amazon/elb_application_lb.py @@ -755,6 +755,14 @@ def create_or_update_elb_listeners(connection, module, elb): # Get listener based on port so we can use ARN looked_up_listener = get_listener(connection, module, elb['LoadBalancerArn'], listener['Port']) + # Delete rules + for rule in rules_to_delete: + try: + connection.delete_rule(RuleArn=rule) + listener_changed = True + except ClientError as e: + module.fail_json(msg=e.message, exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.response)) + # Add rules for rule in rules_to_add: try: @@ -774,14 +782,6 @@ def create_or_update_elb_listeners(connection, module, elb): except ClientError as e: module.fail_json(msg=e.message, exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.response)) - # Delete rules - for rule in rules_to_delete: - try: - connection.delete_rule(RuleArn=rule) - listener_changed = True - except ClientError as e: - module.fail_json(msg=e.message, exception=traceback.format_exc(), **camel_dict_to_snake_dict(e.response)) - return listener_changed