# extra scaling events with ec2\_asg module

**URL:** <https://forum.ansible.com/t/extra-scaling-events-with-ec2-asg-module/17834>\
**Category:** Ansible Project\
**Created:** [March 25, 2015, 1:36pm UTC](https://forum.ansible.com/t/extra-scaling-events-with-ec2-asg-module/17834 "2015-03-25T13:36:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![robb](https://avatars.discourse-cdn.com/v4/letter/r/a183cd/32.png) [@robb](https://forum.ansible.com/u/robb)\
**Post date:** [March 25, 2015, 1:36pm UTC](https://forum.ansible.com/t/extra-scaling-events-with-ec2-asg-module/17834/1 "2015-03-25T13:36:17Z")

</div>

For Ansible 1.9-develop Pull request [601](https://github.com/ansible/ansible-modules-core/pull/601) had the fix for Issue 383, which does affect our production ASG about every two weeks or so. We use the ec2\_asg module to refresh our ASG instances 3 times a day.

I was eager to test. In doing so, I noticed that the replace\_all\_instances or replace\_instances options cause extra set of scaling events. Has anyone else who uses either replace\_ option see this happen? See below for the screen shot which demonstrates the behavior.

We have one instance in two different Availability Zones. So we use a batch size of two (actually a formula based upon the length of the availability\_zones list of the ASG).

Interesting… I just tested with batch\_size: 1. The extra set of scaling events was 1. I.e. one new instance launched and one new instance terminated.

The batch\_size logic is broken. I am going open an Issue in **ansible-modules-core** , but welcome others to note their experience here. I’ll update this topic with a link to the Issue, too.

`

- name: Retrieve Auto Scaling Group properties  
local\_action:  
module: ec2\_asg  
name: “{{ asg\_name }}”  
state: present  
health\_check\_type: ELB  
register: result\_asg

- name: Auto Scaling Group properties  
debug: var=result\_asg

- name: Replace current instances with fresh instances  
local\_action:  
module: ec2\_asg  
name: “{{ asg\_name }}”  
state: present  
min\_size: “{{ result\_asg.min\_size }}”  
max\_size: “{{ result\_asg.max\_size }}”  
desired\_capacity: “{{ result\_asg.desired\_capacity }}”  
health\_check\_type: “{{ result\_asg.health\_check\_type }}”  
lc\_check: no  
replace\_all\_instances: yes  
replace\_batch\_size: “{{ result\_asg.availability\_zones | length() }}”

`

1. and 2. are expected. a. - d. are extra scaling events.

[![](https://lh3.googleusercontent.com/-1bvOCHDYhjU/VRK3Bkz1O-I/AAAAAAAAACs/RCDKklA7Hkc/s1600/EC2_Management_Console.jpg)](https://lh3.googleusercontent.com/-1bvOCHDYhjU/VRK3Bkz1O-I/AAAAAAAAACs/RCDKklA7Hkc/s1600/EC2_Management_Console.jpg)

---

<div class="post-metadata">

**Author:** ![James\_Martin1](https://avatars.discourse-cdn.com/v4/letter/j/0ea827/32.png) [@James\_Martin1](https://forum.ansible.com/u/James_Martin1)\
**Post date:** [March 25, 2015, 3:02pm UTC](https://forum.ansible.com/t/extra-scaling-events-with-ec2-asg-module/17834/2 "2015-03-25T15:02:12Z")

</div>

Looking forward to the github issue – make sure you take a look at the autoscale group and the ELB in the AWS console and see if it gives a description why the instances were terminated. I’ve seen cases where things did not come online fast enough and the ELB marks them as unhealthy and the ASG terminates them.

Thanks,

James

---

<div class="post-metadata">

**Author:** ![robb](https://avatars.discourse-cdn.com/v4/letter/r/a183cd/32.png) [@robb](https://forum.ansible.com/u/robb)\
**Post date:** [March 25, 2015, 5:42pm UTC](https://forum.ansible.com/t/extra-scaling-events-with-ec2-asg-module/17834/3 "2015-03-25T17:42:19Z")

</div>

Thanks James.

All the instances terminated are due to being marked **Unhealthy** by terminate\_batch().

I am using the changes from this PR: [https://github.com/ansible/ansible-modules-core/pull/589](https://github.com/ansible/ansible-modules-core/pull/589), combined with the fixes in PR 601. Rationale: I need `lc_check=no` to cause all instances to get replaced. With the current way it is written in the module lc\_check only works if the active if an instance has a different Launch Config than the one assigned to the ASG. Upon further consideration, I should add a new option instead of overloading the meaning of lc\_check.

---

<div class="post-metadata">

**Author:** ![James\_Martin1](https://avatars.discourse-cdn.com/v4/letter/j/0ea827/32.png) [@James\_Martin1](https://forum.ansible.com/u/James_Martin1)\
**Post date:** [March 30, 2015, 8:44pm UTC](https://forum.ansible.com/t/extra-scaling-events-with-ec2-asg-module/17834/4 "2015-03-30T20:44:25Z")

</div>

I spent some time re-working the algorithm that does the rolling replacement. It is much smarter now, and it shouldn’t cause unecessary scaling events. I’ve also merged the functionality of #589. Would you mind giving it a whirl?

[https://github.com/ansible/ansible-modules-core/pull/1030](https://github.com/ansible/ansible-modules-core/pull/1030)
