Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Howto delete ecs service with ansible

Tags:

ansible

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?

like image 622
Nathan Avatar asked Oct 07 '16 14:10

Nathan


1 Answers

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.

like image 115
Patrick Pötz Avatar answered Nov 06 '22 16:11

Patrick Pötz