From 063a7d6e40d80b32bedafa5a9e35a86b6580297e Mon Sep 17 00:00:00 2001 From: Joseph Torcasso Date: Fri, 3 Jun 2022 11:38:42 -0400 Subject: [PATCH 1/6] add waiters and fix some bugs --- plugins/modules/ecs_service.py | 26 +++- plugins/modules/ecs_task.py | 40 ++++- .../targets/ecs_cluster/tasks/main.yml | 143 +++++++++++++----- 3 files changed, 167 insertions(+), 42 deletions(-) diff --git a/plugins/modules/ecs_service.py b/plugins/modules/ecs_service.py index f7bd5779e18..7f26176558a 100644 --- a/plugins/modules/ecs_service.py +++ b/plugins/modules/ecs_service.py @@ -38,8 +38,10 @@ cluster: description: - The name of the cluster in which the service exists. + - If not specified, the cluster name will be 'default'. required: false type: str + default: 'default' task_definition: description: - The task definition the service will run. @@ -218,6 +220,12 @@ required: false choices: ["DAEMON", "REPLICA"] type: str + wait: + description: + - Whether or not to wait for the desired state. + type: bool + default: false + version_added: 3.4.0 extends_documentation_fragment: - amazon.aws.aws - amazon.aws.ec2 @@ -608,8 +616,9 @@ def is_matching_service(self, expected, existing): if expected['task_definition'] != existing['taskDefinition'].split('/')[-1]: return False - if expected.get('health_check_grace_period_seconds') != existing.get('healthCheckGracePeriodSeconds'): - return False + if expected.get('health_check_grace_period_seconds'): + if expected.get('health_check_grace_period_seconds') != existing.get('healthCheckGracePeriodSeconds'): + return False if (expected['load_balancers'] or []) != existing['loadBalancers']: return False @@ -717,7 +726,7 @@ def main(): argument_spec = dict( state=dict(required=True, choices=['present', 'absent', 'deleting']), name=dict(required=True, type='str', aliases=['service']), - cluster=dict(required=False, type='str'), + cluster=dict(required=False, type='str', default='default'), task_definition=dict(required=False, type='str'), load_balancers=dict(required=False, default=[], type='list', elements='dict'), desired_count=dict(required=False, type='int'), @@ -728,6 +737,7 @@ def main(): force_new_deployment=dict(required=False, default=False, type='bool'), force_deletion=dict(required=False, default=False, type='bool'), deployment_configuration=dict(required=False, default={}, type='dict'), + wait=dict(required=False, default=False, type='bool'), placement_constraints=dict( required=False, default=[], @@ -912,6 +922,16 @@ def main(): module.params['cluster'], module.params['force_deletion'], ) + + # Wait for service to be INACTIVE prior to exiting + if module.params['wait']: + + params = {} + params['services'] = [module.params['name']] + params['cluster'] = module.params['cluster'] + + service_mgr.ecs.get_waiter('services_inactive').wait(**params) + except botocore.exceptions.ClientError as e: module.fail_json_aws(e, msg="Couldn't delete service") results['changed'] = True diff --git a/plugins/modules/ecs_task.py b/plugins/modules/ecs_task.py index b4c625df712..9f8dddec1e7 100644 --- a/plugins/modules/ecs_task.py +++ b/plugins/modules/ecs_task.py @@ -28,8 +28,10 @@ cluster: description: - The name of the cluster to run the task on. - required: True + - If not specified, the cluster name will be 'default'. + required: False type: str + default: 'default' task_definition: description: - The task definition to start, run or stop. @@ -90,6 +92,12 @@ - Tags that will be added to ecs tasks on start and run required: false aliases: ['resource_tags'] + wait: + description: + - Whether or not to wait for the desired state. + type: bool + default: false + version_added: 3.4.0 extends_documentation_fragment: - amazon.aws.aws - amazon.aws.ec2 @@ -342,7 +350,7 @@ def ecs_task_long_format_enabled(self): def main(): argument_spec = dict( operation=dict(required=True, choices=['run', 'start', 'stop']), - cluster=dict(required=True, type='str'), # R S P + cluster=dict(required=False, type='str', default='default'), # R S P task_definition=dict(required=False, type='str'), # R* S* overrides=dict(required=False, type='dict'), # R S count=dict(required=False, type='int'), # R @@ -352,6 +360,7 @@ def main(): network_configuration=dict(required=False, type='dict'), launch_type=dict(required=False, choices=['EC2', 'FARGATE']), tags=dict(required=False, type='dict', aliases=['resource_tags']) + wait=dict(required=False, default=False, type='bool'), ) module = AnsibleAWSModule(argument_spec=argument_spec, supports_check_mode=True, @@ -393,7 +402,9 @@ def main(): results['task'] = existing else: if not module.check_mode: - results['task'] = service_mgr.run_task( + + # run_task returns a list of tasks created + tasks = service_mgr.run_task( module.params['cluster'], module.params['task_definition'], module.params['overrides'], @@ -402,6 +413,18 @@ def main(): module.params['launch_type'], module.params['tags'], ) + + # Wait for task(s) to be running prior to exiting + if module.params['wait']: + + params = {} + params['tasks'] = [task['taskArn'] for task in tasks] + params['cluster'] = module.params['cluster'] + + service_mgr.ecs.get_waiter('tasks_running').wait(**params) + + results['task'] = tasks + results['changed'] = True elif module.params['operation'] == 'start': @@ -418,6 +441,7 @@ def main(): module.params['started_by'], module.params['tags'], ) + results['changed'] = True elif module.params['operation'] == 'stop': @@ -431,6 +455,16 @@ def main(): module.params['cluster'], module.params['task'] ) + + # Wait for task to be stopped prior to exiting + if module.params['wait']: + + params = {} + params['tasks'] = [module.params['task']] + params['cluster'] = module.params['cluster'] + + service_mgr.ecs.get_waiter('tasks_stopped').wait(**params) + results['changed'] = True module.exit_json(**results) diff --git a/tests/integration/targets/ecs_cluster/tasks/main.yml b/tests/integration/targets/ecs_cluster/tasks/main.yml index 7f49374b532..7f3a1deee85 100644 --- a/tests/integration/targets/ecs_cluster/tasks/main.yml +++ b/tests/integration/targets/ecs_cluster/tasks/main.yml @@ -326,15 +326,40 @@ role: "ecsServiceRole" register: ecs_service_scale_down - - name: pause to allow service to scale down - pause: - seconds: 60 + - name: assert that ECS service is scaled down + assert: + that: + - ecs_service_scale_down.changed + - ecs_service_scale_down.service.desiredCount == 0 + + - name: scale down ECS service again + ecs_service: + state: present + name: "{{ ecs_service_name }}" + cluster: "{{ ecs_cluster_name }}" + task_definition: "{{ ecs_task_name }}:{{ ecs_task_definition.taskdefinition.revision }}" + desired_count: 0 + deployment_configuration: "{{ ecs_service_deployment_configuration }}" + placement_strategy: "{{ ecs_service_placement_strategy }}" + load_balancers: + - targetGroupArn: "{{ elb_target_group_instance.target_group_arn }}" + containerName: "{{ ecs_task_name }}" + containerPort: "{{ ecs_task_container_port }}" + role: "ecsServiceRole" + register: ecs_service_scale_down + + - name: assert no change + assert: + that: + - not ecs_service_scale_down.changed + - ecs_service_scale_down.service.desiredCount == 0 - name: delete ECS service definition ecs_service: state: absent name: "{{ ecs_service_name }}" cluster: "{{ ecs_cluster_name }}" + wait: yes register: delete_ecs_service - name: assert that deleting ECS service worked @@ -342,10 +367,17 @@ that: - delete_ecs_service.changed - - name: assert that deleting ECS service worked + - name: delete ECS service definition again + ecs_service: + state: absent + name: "{{ ecs_service_name }}" + cluster: "{{ ecs_cluster_name }}" + register: delete_ecs_service + + - name: assert no change assert: that: - - delete_ecs_service.changed + - not delete_ecs_service.changed - name: create VPC-networked task definition with host port set to 0 (expected to fail) ecs_taskdefinition: @@ -382,10 +414,6 @@ that: - "ecs_taskdefinition_info.network_mode == 'awsvpc'" - - name: pause to allow service to scale down - pause: - seconds: 60 - - name: create ECS service definition with network configuration ecs_service: state: present @@ -428,7 +456,6 @@ state: present register: ecs_service_creation_hcgp - - name: health_check_grace_period_seconds sets HealthChecGracePeriodSeconds assert: that: @@ -525,7 +552,7 @@ - name: attempt to get facts from missing task definition ecs_taskdefinition_info: task_definition: "{{ ecs_task_name }}-vpc:{{ ecs_task_definition.taskdefinition.revision + 1}}" - + - name: Create another task definition with placement constraints ecs_taskdefinition: containers: "{{ ecs_task_containers }}" @@ -540,19 +567,31 @@ - ecs_task_definition_constraints is changed - ecs_task_definition_constraints.taskdefinition.placementConstraints[0].type == "{{ ecs_taskdefinition_placement_constraints[0].type }}" - ecs_task_definition_constraints.taskdefinition.placementConstraints[0].expression == "{{ ecs_taskdefinition_placement_constraints[0].expression }}" - + - name: Remove ecs task definition with placement constraints ecs_taskdefinition: containers: "{{ ecs_task_containers }}" arn: "{{ ecs_task_definition_constraints.taskdefinition.taskDefinitionArn }}" state: absent register: ecs_task_definition_constraints_delete - + - name: Check that task definition has been deleted assert: that: - ecs_task_definition_constraints_delete is changed + - name: Remove ecs task definition with placement constraints again + ecs_taskdefinition: + containers: "{{ ecs_task_containers }}" + arn: "{{ ecs_task_definition_constraints.taskdefinition.taskDefinitionArn }}" + state: absent + register: ecs_task_definition_constraints_delete + + - name: Assert no change + assert: + that: + - ecs_task_definition_constraints_delete is not changed + # ============================================================ # Begin tests for Fargate @@ -674,6 +713,8 @@ that: - 'ecs_fargate_service_network_with_awsvpc.service.networkConfiguration.awsvpcConfiguration.assignPublicIp == "ENABLED"' + ### FIX - run tasks are all failing with CannotPullContainerError in AWS + ### So using wait: True fails when waiting for tasks to be started - name: create fargate ECS task with run task ecs_task: operation: run @@ -687,8 +728,35 @@ - '{{ setup_sg.group_id }}' assign_public_ip: true started_by: ansible_user + # wait: yes register: fargate_run_task_output + - name: Assert changed + assert: + that: + - fargate_run_task_output.changed + + # - name: create fargate ECS task with run task again + # ecs_task: + # operation: run + # cluster: "{{ ecs_cluster_name }}" + # task_definition: "{{ ecs_task_name }}-vpc" + # launch_type: FARGATE + # count: 1 + # network_configuration: + # subnets: "{{ setup_subnet.results | map(attribute='subnet.id') | list }}" + # security_groups: + # - '{{ setup_sg.group_id }}' + # assign_public_ip: true + # started_by: ansible_user + # register: fargate_run_task_output + + # - name: Assert no change + # assert: + # that: + # - not fargate_run_task_output.changed + + ### This does not fail - name: create fargate ECS task with run task and tags (LF disabled) (should fail) ecs_task: operation: run @@ -708,6 +776,11 @@ register: fargate_run_task_output_with_tags_fail ignore_errors: yes + # - name: assert that using Fargate ECS service fails + # assert: + # that: + # - fargate_run_task_output_with_tags_fail is failed + - name: enable taskLongArnFormat command: aws ecs put-account-setting --name taskLongArnFormat --value enabled environment: @@ -865,26 +938,19 @@ ignore_errors: yes register: ecs_service_scale_down - - name: stop Fargate ECS task - ecs_task: - task: "{{ fargate_run_task_output.task[0].taskArn }}" - task_definition: "{{ ecs_task_name }}-vpc" - operation: stop - cluster: "{{ ecs_cluster_name }}" - ignore_errors: yes - - - name: stop Fargate ECS task + - name: stop Fargate ECS tasks ecs_task: - task: "{{ fargate_run_task_output_with_tags.task[0].taskArn }}" + task: "{{ item.task[0].taskArn }}" task_definition: "{{ ecs_task_name }}-vpc" operation: stop cluster: "{{ ecs_cluster_name }}" + wait: yes ignore_errors: yes - - - name: pause to allow services to scale down - pause: - seconds: 60 - when: ecs_service_scale_down is not failed + with_items: + - "{{ fargate_run_task_output }}" + - "{{ fargate_run_task_output_with_tags }}" + - "{{ fargate_run_task_output_with_assign_ip }}" + - "{{ fargate_run_task_output_with_tags_fail }}" - name: remove ecs service ecs_service: @@ -892,6 +958,7 @@ cluster: "{{ ecs_cluster_name }}" name: "{{ ecs_service_name }}" force_deletion: yes + wait: yes ignore_errors: yes - name: remove second ecs service @@ -900,6 +967,7 @@ cluster: "{{ ecs_cluster_name }}" name: "{{ ecs_service_name }}2" force_deletion: yes + wait: yes ignore_errors: yes - name: remove mft ecs service @@ -908,6 +976,7 @@ cluster: "{{ ecs_cluster_name }}" name: "{{ ecs_service_name }}-mft" force_deletion: yes + wait: yes ignore_errors: yes - name: remove scheduling_strategy ecs service @@ -916,6 +985,7 @@ cluster: "{{ ecs_cluster_name }}" name: "{{ ecs_service_name }}-replica" force_deletion: yes + wait: yes ignore_errors: yes - name: remove fargate ECS service @@ -924,6 +994,7 @@ name: "{{ ecs_service_name }}4" cluster: "{{ ecs_cluster_name }}" force_deletion: yes + wait: yes ignore_errors: yes register: ecs_fargate_service_network_with_awsvpc @@ -965,6 +1036,14 @@ state: absent ignore_errors: yes + - name: remove ec2 ecs task definition + ecs_taskdefinition: + containers: "{{ ecs_fargate_task_containers }}" + family: "{{ ecs_task_name }}-vpc" + revision: "{{ ecs_ec2_task_definition.taskdefinition.revision }}" + state: absent + ignore_errors: yes + - name: remove ecs task definition for absent with arn ecs_taskdefinition: containers: "{{ ecs_task_containers }}" @@ -981,11 +1060,6 @@ ignore_errors: yes register: elb_application_lb_remove - - name: pause to allow target group to be disassociated - pause: - seconds: 30 - when: not elb_application_lb_remove is failed - - name: remove setup keypair ec2_key: name: '{{ resource_prefix }}_ecs_cluster' @@ -998,9 +1072,6 @@ state: absent ignore_errors: yes register: this_deletion - retries: 12 - delay: 10 - until: this_deletion is not failed - name: remove security groups ec2_group: From fdff1b3df22f2ef5942712e5ea9829f1b0cca5b2 Mon Sep 17 00:00:00 2001 From: Joseph Torcasso Date: Fri, 3 Jun 2022 12:00:20 -0400 Subject: [PATCH 2/6] add changelog --- .../1209-ecs_service-add-waiters-and-small-bugfixes.yml | 8 ++++++++ plugins/modules/ecs_task.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/1209-ecs_service-add-waiters-and-small-bugfixes.yml diff --git a/changelogs/fragments/1209-ecs_service-add-waiters-and-small-bugfixes.yml b/changelogs/fragments/1209-ecs_service-add-waiters-and-small-bugfixes.yml new file mode 100644 index 00000000000..b3a40055e6f --- /dev/null +++ b/changelogs/fragments/1209-ecs_service-add-waiters-and-small-bugfixes.yml @@ -0,0 +1,8 @@ +bugfixes: + - ecs_service - only compare ``health_check_grace_period_seconds`` parameter when it's supplied (https://github.com/ansible-collections/community.aws/pull/1209). + - ecs_task - dont require ``cluster`` parameter and default it to ``default`` (https://github.com/ansible-collections/community.aws/pull/1209). + +minor_changes: + - ecs_service - add default value of ``default`` to ``cluster`` (https://github.com/ansible-collections/community.aws/pull/1209). + - ecs_service - add ``wait`` parameter and waiter for deleting services (https://github.com/ansible-collections/community.aws/pull/1209). + - ecs_task - add ``wait`` parameter and waiter for running and stopping tasks (https://github.com/ansible-collections/community.aws/pull/1209). diff --git a/plugins/modules/ecs_task.py b/plugins/modules/ecs_task.py index 9f8dddec1e7..9ff0a153a5b 100644 --- a/plugins/modules/ecs_task.py +++ b/plugins/modules/ecs_task.py @@ -359,7 +359,7 @@ def main(): started_by=dict(required=False, type='str'), # R S network_configuration=dict(required=False, type='dict'), launch_type=dict(required=False, choices=['EC2', 'FARGATE']), - tags=dict(required=False, type='dict', aliases=['resource_tags']) + tags=dict(required=False, type='dict', aliases=['resource_tags']), wait=dict(required=False, default=False, type='bool'), ) From 1bd70c6d85dd04e943161530b0a245b9fd950ee8 Mon Sep 17 00:00:00 2001 From: Joseph Torcasso Date: Fri, 3 Jun 2022 19:05:11 -0400 Subject: [PATCH 3/6] move bugfixes to different PR for backporting purposes --- .../1209-ecs_service-add-waiters-and-small-bugfixes.yml | 8 -------- changelogs/fragments/1209-ecs_service-add-waiters.yml | 3 +++ plugins/modules/ecs_service.py | 9 +++------ plugins/modules/ecs_task.py | 6 ++---- 4 files changed, 8 insertions(+), 18 deletions(-) delete mode 100644 changelogs/fragments/1209-ecs_service-add-waiters-and-small-bugfixes.yml create mode 100644 changelogs/fragments/1209-ecs_service-add-waiters.yml diff --git a/changelogs/fragments/1209-ecs_service-add-waiters-and-small-bugfixes.yml b/changelogs/fragments/1209-ecs_service-add-waiters-and-small-bugfixes.yml deleted file mode 100644 index b3a40055e6f..00000000000 --- a/changelogs/fragments/1209-ecs_service-add-waiters-and-small-bugfixes.yml +++ /dev/null @@ -1,8 +0,0 @@ -bugfixes: - - ecs_service - only compare ``health_check_grace_period_seconds`` parameter when it's supplied (https://github.com/ansible-collections/community.aws/pull/1209). - - ecs_task - dont require ``cluster`` parameter and default it to ``default`` (https://github.com/ansible-collections/community.aws/pull/1209). - -minor_changes: - - ecs_service - add default value of ``default`` to ``cluster`` (https://github.com/ansible-collections/community.aws/pull/1209). - - ecs_service - add ``wait`` parameter and waiter for deleting services (https://github.com/ansible-collections/community.aws/pull/1209). - - ecs_task - add ``wait`` parameter and waiter for running and stopping tasks (https://github.com/ansible-collections/community.aws/pull/1209). diff --git a/changelogs/fragments/1209-ecs_service-add-waiters.yml b/changelogs/fragments/1209-ecs_service-add-waiters.yml new file mode 100644 index 00000000000..cfe3df4af58 --- /dev/null +++ b/changelogs/fragments/1209-ecs_service-add-waiters.yml @@ -0,0 +1,3 @@ +minor_changes: + - ecs_service - add ``wait`` parameter and waiter for deleting services (https://github.com/ansible-collections/community.aws/pull/1209). + - ecs_task - add ``wait`` parameter and waiter for running and stopping tasks (https://github.com/ansible-collections/community.aws/pull/1209). diff --git a/plugins/modules/ecs_service.py b/plugins/modules/ecs_service.py index 7f26176558a..ddbfd323c05 100644 --- a/plugins/modules/ecs_service.py +++ b/plugins/modules/ecs_service.py @@ -38,10 +38,8 @@ cluster: description: - The name of the cluster in which the service exists. - - If not specified, the cluster name will be 'default'. required: false type: str - default: 'default' task_definition: description: - The task definition the service will run. @@ -616,9 +614,8 @@ def is_matching_service(self, expected, existing): if expected['task_definition'] != existing['taskDefinition'].split('/')[-1]: return False - if expected.get('health_check_grace_period_seconds'): - if expected.get('health_check_grace_period_seconds') != existing.get('healthCheckGracePeriodSeconds'): - return False + if expected.get('health_check_grace_period_seconds') != existing.get('healthCheckGracePeriodSeconds'): + return False if (expected['load_balancers'] or []) != existing['loadBalancers']: return False @@ -726,7 +723,7 @@ def main(): argument_spec = dict( state=dict(required=True, choices=['present', 'absent', 'deleting']), name=dict(required=True, type='str', aliases=['service']), - cluster=dict(required=False, type='str', default='default'), + cluster=dict(required=False, type='str'), task_definition=dict(required=False, type='str'), load_balancers=dict(required=False, default=[], type='list', elements='dict'), desired_count=dict(required=False, type='int'), diff --git a/plugins/modules/ecs_task.py b/plugins/modules/ecs_task.py index 9ff0a153a5b..701084831fd 100644 --- a/plugins/modules/ecs_task.py +++ b/plugins/modules/ecs_task.py @@ -28,10 +28,8 @@ cluster: description: - The name of the cluster to run the task on. - - If not specified, the cluster name will be 'default'. - required: False + required: True type: str - default: 'default' task_definition: description: - The task definition to start, run or stop. @@ -350,7 +348,7 @@ def ecs_task_long_format_enabled(self): def main(): argument_spec = dict( operation=dict(required=True, choices=['run', 'start', 'stop']), - cluster=dict(required=False, type='str', default='default'), # R S P + cluster=dict(required=True, type='str'), # R S P task_definition=dict(required=False, type='str'), # R* S* overrides=dict(required=False, type='dict'), # R S count=dict(required=False, type='int'), # R From f435e7a754fa7a26e6f0cca5cbcc9229b2fcc32a Mon Sep 17 00:00:00 2001 From: Joseph Torcasso Date: Mon, 6 Jun 2022 12:30:17 -0400 Subject: [PATCH 4/6] update wait description --- plugins/modules/ecs_service.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/modules/ecs_service.py b/plugins/modules/ecs_service.py index ddbfd323c05..18e3b1d6eb3 100644 --- a/plugins/modules/ecs_service.py +++ b/plugins/modules/ecs_service.py @@ -220,7 +220,8 @@ type: str wait: description: - - Whether or not to wait for the desired state. + - Whether or not to wait for the service to be inactive. + - Waits only when I(state) is C(absent). type: bool default: false version_added: 3.4.0 From 08010b48be6b865aa2ed1f2a3ac748e1d3dc13d3 Mon Sep 17 00:00:00 2001 From: Joseph Torcasso Date: Tue, 7 Jun 2022 11:21:39 -0400 Subject: [PATCH 5/6] catch WaiterError --- plugins/modules/ecs_service.py | 20 +++++++++++++------- plugins/modules/ecs_task.py | 26 ++++++++++++++++---------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/plugins/modules/ecs_service.py b/plugins/modules/ecs_service.py index 18e3b1d6eb3..f86e6d9227c 100644 --- a/plugins/modules/ecs_service.py +++ b/plugins/modules/ecs_service.py @@ -923,15 +923,21 @@ def main(): # Wait for service to be INACTIVE prior to exiting if module.params['wait']: - - params = {} - params['services'] = [module.params['name']] - params['cluster'] = module.params['cluster'] - - service_mgr.ecs.get_waiter('services_inactive').wait(**params) - + waiter = service_mgr.ecs.get_waiter('services_inactive') + try: + waiter.wait( + services=[module.params['name']], + cluster=module.params['cluster'], + WaiterConfig={ + 'Delay': module.params['delay'], + 'MaxAttempts': module.params['repeat'] + } + ) + except botocore.exceptions.WaiterError as e: + module.fail_json_aws(e, 'Timeout waiting for service removal') except botocore.exceptions.ClientError as e: module.fail_json_aws(e, msg="Couldn't delete service") + results['changed'] = True elif module.params['state'] == 'deleting': diff --git a/plugins/modules/ecs_task.py b/plugins/modules/ecs_task.py index 701084831fd..abe1582c9c9 100644 --- a/plugins/modules/ecs_task.py +++ b/plugins/modules/ecs_task.py @@ -415,11 +415,14 @@ def main(): # Wait for task(s) to be running prior to exiting if module.params['wait']: - params = {} - params['tasks'] = [task['taskArn'] for task in tasks] - params['cluster'] = module.params['cluster'] - - service_mgr.ecs.get_waiter('tasks_running').wait(**params) + waiter = service_mgr.ecs.get_waiter('tasks_running') + try: + waiter.wait( + tasks=[task['taskArn'] for task in tasks], + cluster=module.params['cluster'], + ) + except botocore.exceptions.WaiterError as e: + module.fail_json_aws(e, 'Timeout waiting for tasks to run') results['task'] = tasks @@ -457,11 +460,14 @@ def main(): # Wait for task to be stopped prior to exiting if module.params['wait']: - params = {} - params['tasks'] = [module.params['task']] - params['cluster'] = module.params['cluster'] - - service_mgr.ecs.get_waiter('tasks_stopped').wait(**params) + waiter = service_mgr.ecs.get_waiter('tasks_stopped') + try: + waiter.wait( + tasks=[module.params['task']], + cluster=module.params['cluster'], + ) + except botocore.exceptions.WaiterError as e: + module.fail_json_aws(e, 'Timeout waiting for task to stop') results['changed'] = True From ccce41ab29eb8dba68bcdb89a7d99e0a893ee972 Mon Sep 17 00:00:00 2001 From: Mark Chappell Date: Wed, 29 Jun 2022 08:29:56 +0200 Subject: [PATCH 6/6] Bump version_added Co-authored-by: Markus Bergholz --- plugins/modules/ecs_service.py | 2 +- plugins/modules/ecs_task.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/modules/ecs_service.py b/plugins/modules/ecs_service.py index f86e6d9227c..52b7bcd9a56 100644 --- a/plugins/modules/ecs_service.py +++ b/plugins/modules/ecs_service.py @@ -224,7 +224,7 @@ - Waits only when I(state) is C(absent). type: bool default: false - version_added: 3.4.0 + version_added: 4.1.0 extends_documentation_fragment: - amazon.aws.aws - amazon.aws.ec2 diff --git a/plugins/modules/ecs_task.py b/plugins/modules/ecs_task.py index abe1582c9c9..893bf380ba6 100644 --- a/plugins/modules/ecs_task.py +++ b/plugins/modules/ecs_task.py @@ -95,7 +95,7 @@ - Whether or not to wait for the desired state. type: bool default: false - version_added: 3.4.0 + version_added: 4.1.0 extends_documentation_fragment: - amazon.aws.aws - amazon.aws.ec2