0

For cost reasons, our ASG's in the QA environment run with desired/min/max capacity set to "1". That's not the case for Production but since we use the same code for QA and Prod deployment (minus a few variables of course) this is causing problems with the QA automation jobs.

- name: create autoscale groups original_lc
  ec2_asg:
    name: "{{ app_name }}"
    target_group_arns: "{{alb_target_group_facts.target_groups[0].target_group_arn}}"
    launch_config_name: "{{ launch_config.name }}"
    min_size: 1
    max_size: 1
    desired_capacity: 1
    region: "{{ region }}"
    vpc_zone_identifier: "{{ subnets | join(',') }}"
    health_check_type: "{{health_check}}"
    replace_all_instances: yes
    wait_for_instances: false
    replace_batch_size: '{{ rollover_size }}'
    lc_check: false
    default_cooldown: "{{default_cooldown}}"
    health_check_period: "{{health_check_period}}"
    notification_topic: "{{redeem_notification_group}}"
    tags:
      - Name : "{{ app_name }}"
      - Application: "{{ tag_Application }}"
      - Product_Owner: "{{ tag_Product_Owner }}"
      - Resource_Owner: "{{ tag_Resource_Owner }}"
      - Role: "{{ tag_Role }}"
      - Service_Category: "{{ tag_Service_Category }}"
  register: asg_original_lc

On the first run, the "ec2_asg" module creates the group properly, with the correct desired/min/max settings.

But when we run the job a second time to update the same ASG, it changes desired/min/max to "2" in AWS. We don't want that. We just want it to rotate out that one instance in the group. Is there a way to achieve that?

  • Because ansible does not maintain state, it must discover the current state of affairs if you wish it to leave some things as they are right now. You will find [`ec2_asg_info:`](https://docs.ansible.com/ansible/2.10/collections/community/aws/ec2_asg_info_module.html) helpful in knowing what the current desired/min/max values are – mdaniel Mar 10 '21 at 17:05
  • @mdaniel I'm not sure I follow. Will using ec2_asg_info beforehand make it so it wont change the desired/min/max count? – captain_booboo Mar 10 '21 at 17:48
  • It, by itself, will not do that. But as I understand your question, you have some constants in `min_size: 1` and the reality of the ASG is it is not always 1; so by calling `- {ec2_asg_info: {}, register: my_asg}` you can then `min_size: "{{ my_asg.whatever.min_size }}"` and retain its current sizing while changing other parts – mdaniel Mar 11 '21 at 02:55
  • @mdaniel Interesting. I tried your suggestion but got the same result. The desire/min/max again got pushed from 1 to 2. Unless I log in and manually adjust the count back to 1, the task ends up failing, presumably because it's expecting 1 instance and seeing 2. – captain_booboo Mar 11 '21 at 05:01
  • Well, without your code or any further information than can be shoved in the comments, I don't know what to tell you – mdaniel Mar 11 '21 at 15:48

0 Answers0