From d343a3abd1384b20ad4af0026602db2d45e730c5 Mon Sep 17 00:00:00 2001 From: Markus Juopperi Date: Tue, 5 Sep 2017 20:47:33 +0300 Subject: [PATCH] elb_application_lb: when purging rules make deletion the first step (#28749) This prevents errors when adding new rules that conflict with existing ones that will be deleted. For example this allows adding a new rule with the same priority of a rule that will be purged. --- .../modules/cloud/amazon/elb_application_lb.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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