From a1d0b79fe8f882d4f6b5baee5135615006978045 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Tue, 14 Mar 2023 17:49:20 +0100 Subject: [PATCH] Make sure update is wrapped in a try --- .../488-ecs_service-support_exec.yml | 1 + plugins/modules/ecs_service.py | 42 ++++++++++--------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/changelogs/fragments/488-ecs_service-support_exec.yml b/changelogs/fragments/488-ecs_service-support_exec.yml index 02b76b03b62..70bc3256d4d 100644 --- a/changelogs/fragments/488-ecs_service-support_exec.yml +++ b/changelogs/fragments/488-ecs_service-support_exec.yml @@ -1,2 +1,3 @@ minor_changes: - ecs_service - added new parameter ``enable_execute_command`` (https://github.com/ansible-collections/community.aws/pull/488). +- ecs_service - handle SDK errors more cleanly on update failures (https://github.com/ansible-collections/community.aws/pull/488). diff --git a/plugins/modules/ecs_service.py b/plugins/modules/ecs_service.py index d8890b9524a..2009dc3b54a 100644 --- a/plugins/modules/ecs_service.py +++ b/plugins/modules/ecs_service.py @@ -927,6 +927,7 @@ def update_service( params['loadBalancers'] = load_balancers response = self.ecs.update_service(**params) + return self.jsonize(response['service']) def jsonize(self, service): @@ -1129,24 +1130,27 @@ def main(): if task_definition is None and module.params['force_new_deployment']: task_definition = existing['taskDefinition'] - # update required - response = service_mgr.update_service( - module.params["name"], - module.params["cluster"], - task_definition, - module.params["desired_count"], - deploymentConfiguration, - module.params["placement_constraints"], - module.params["placement_strategy"], - network_configuration, - module.params["health_check_grace_period_seconds"], - module.params["force_new_deployment"], - capacityProviders, - updatedLoadBalancers, - module.params["purge_placement_constraints"], - module.params["purge_placement_strategy"], - module.params["enable_execute_command"], - ) + try: + # update required + response = service_mgr.update_service( + module.params["name"], + module.params["cluster"], + task_definition, + module.params["desired_count"], + deploymentConfiguration, + module.params["placement_constraints"], + module.params["placement_strategy"], + network_configuration, + module.params["health_check_grace_period_seconds"], + module.params["force_new_deployment"], + capacityProviders, + updatedLoadBalancers, + module.params["purge_placement_constraints"], + module.params["purge_placement_strategy"], + module.params["enable_execute_command"], + ) + except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: + module.fail_json_aws(e, msg="Couldn't create service") else: try: @@ -1173,7 +1177,7 @@ def main(): module.params["propagate_tags"], module.params["enable_execute_command"], ) - except botocore.exceptions.ClientError as e: + except (botocore.exceptions.BotoCoreError, botocore.exceptions.ClientError) as e: module.fail_json_aws(e, msg="Couldn't create service") if response.get('tags', None):