ansible / proposals

Repository for sharing and tracking progress on enhancement proposals for Ansible.
Creative Commons Zero v1.0 Universal
93 stars 19 forks source link

Allow updating ECS/Fargate desired count without defining tasks #157

Closed kraduk closed 3 years ago

kraduk commented 5 years ago

Proposal: Allow updating ECS/Fargate desired count without defining tasks

Author: @kraduk

Date: 2019-02-06

Motivation

I have a bunch of ECS/Fargate services defined. For some reason I want to be temporarily disable all/some of these tasks. This is easy from AWS point of view as I just set the service desired count to 0.

Problem

Background:

We have an enforcing script that goes around shutting down non live stuff out of office hours. Due to its nature, it does not have knowledge of how the services should be defined/configured. It just looks at tags, and turns things on and off based on what it sees. Therefore destroying and recreating from known config is not an option. This works fine for RDS/Ec2 instances, but is sub optimal for our fargate services.

Issue: On first look you can disable fargate services with the ecs_service module, when used in conjunction with ecs_service_facts. However you hit a potential snag as you cant update the desired service count, without a state option set to present. This then enforces setting the task definition. This seems to be like this as the module has been created from the service creation viewpoint where you would obviously need a task definition. This doesn't make sense in this context though. Yes we can work out the task definitions with various modules but it seems like redundant code and work here. The work around I currently use is along the lines of the below, but breaking into shell isnt great

    - name: Get Fargate details
      ecs_service_facts:
        cluster: Staging
        region: "{{aws_region}}"
      register: ecs_services

    - debug:
        msg: "ECS Services are: {{ ecs_services.services | to_nice_json }}"

    - name: Stop services
      #ecs_service:
      #  name: "{{item}}"
      #  desired_count: 0
        #state: present
      shell: |
        aws ecs update-service \
          --cluster Staging \
          --service "{{item}}" \
          --desired-count 0
      environment:
        AWS_DEFAULT_REGION: "{{aws_region}}"
      with_items: "{{ecs_services.services}}"

Solution proposal

later on (the desired count is usually stored in a tag, which we can retrieve easily)

willthames commented 5 years ago

Would you be able to reraise this issue in ansible/ansible rather than under proposals (proposals is really for much wider reaching changes than changes to a single module)

I do have some thoughts on how we can implement this but don't want to add noise to this repository.