I am trying to delete an ecs service with ansible:
- name: Delete the Service
ecs_service:
name: "{{ service_name }}"
cluster: "{{ cluster_name }}"
state: absent
It fails with:
An error occurred (InvalidParameterException) when calling the DeleteService operation: The service cannot be stopped while the primary deployment is scaled above 0.
So the solution would be to set the "desired_count" to 0 before deleting the service. But how do I do that ansible? Or, what is the correct way of deleting a running ecs service in ansible?
I faced the same problem and figured out how to avoid this problem. As you've already figured out: The "desired count" value has to be set to '0'.
Unfortunately in Ansible you can do this only in a 2-step-way like this:
---
- hosts: localhost
connection: local
gather_facts: False`
tasks:
#update the service as you would do in console or cli,
# so that desired count is set to 0
- ecs_service:
name: jenkins-service
state: present
cluster: jenkins-cluster
desired_count: 0
task_definition: jenkins-task
#now you're able to delete the service definition.
- ecs_service:
name: jenkins-service
state: absent
cluster: jenkins-cluster
I'm sorry for my bad markdown skills. But I hope that helps though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With