# ec2 exact\_count and stopped instances

**URL:** <https://forum.ansible.com/t/ec2-exact-count-and-stopped-instances/17874>\
**Category:** Ansible Project\
**Created:** [March 30, 2015, 11:53pm UTC](https://forum.ansible.com/t/ec2-exact-count-and-stopped-instances/17874 "2015-03-30T23:53:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steven\_Ringo](https://avatars.discourse-cdn.com/v4/letter/s/bc79bd/32.png) [@Steven\_Ringo](https://forum.ansible.com/u/Steven_Ringo)\
**Post date:** [March 30, 2015, 11:53pm UTC](https://forum.ansible.com/t/ec2-exact-count-and-stopped-instances/17874/1 "2015-03-30T23:53:27Z")

</div>

Hi,

Machines that are powered off but match the tags in the EC2 module are not recognised by exact\_count.

Consider:

- A script provisioning an instance with exact\_count of 1 and associated tags is run.
- When run a second time, as expected the script does not provision another instance.
- However if the machine is stopped, and then the script is run again, another instance is provisioned.

The current implementation of exact\_count assumes having a stopped machine should behave as if it does not exist, and will therefore provision another.

I would prefer to see machine state be considered as part of the exact\_count match. Use of the state tag as part of the exact\_count criteria seems to be a good option. Current Ansible does not allow this — a _parameters are mutually exclusive: [‘exact\_count’, ‘state’])_ exception is thrown.

Is there something I am missing, or perhaps another way to ensure that the machine is not reprovisioned when stopped.

Happy to attempt to modify the module and submit a PR, but wanted your thoughts first.

Thanks so much,

Steve

---

<div class="post-metadata">

**Author:** ![Majid\_al-Dosari](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@Majid\_al-Dosari](https://forum.ansible.com/u/Majid_al-Dosari)\
**Post date:** [August 26, 2015, 1:43pm UTC](https://forum.ansible.com/t/ec2-exact-count-and-stopped-instances/17874/2 "2015-08-26T13:43:33Z")

</div>

i agree. this bothers me too.

---

<div class="post-metadata">

**Author:** ![Majid\_al-Dosari](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@Majid\_al-Dosari](https://forum.ansible.com/u/Majid_al-Dosari)\
**Post date:** [August 27, 2015, 12:56pm UTC](https://forum.ansible.com/t/ec2-exact-count-and-stopped-instances/17874/3 "2015-08-27T12:56:35Z")

</div>

aha [https://github.com/ansible/ansible-modules-core/issues/138](https://github.com/ansible/ansible-modules-core/issues/138)

---

<div class="post-metadata">

**Author:** ![Greg\_DeKoenigsberg1](https://avatars.discourse-cdn.com/v4/letter/g/838e76/32.png) [@Greg\_DeKoenigsberg1](https://forum.ansible.com/u/Greg_DeKoenigsberg1)\
**Post date:** [August 27, 2015, 2:08pm UTC](https://forum.ansible.com/t/ec2-exact-count-and-stopped-instances/17874/4 "2015-08-27T14:08:57Z")

</div>

> aha [https://github.com/ansible/ansible-modules-core/issues/138](https://github.com/ansible/ansible-modules-core/issues/138)

That goes through quite a few changes and ends up with a merge here:

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

--g

---

<div class="post-metadata">

**Author:** ![Rohit\_Kothari](https://avatars.discourse-cdn.com/v4/letter/r/ccd318/32.png) [@Rohit\_Kothari](https://forum.ansible.com/u/Rohit_Kothari)\
**Post date:** [May 29, 2016, 2:40am UTC](https://forum.ansible.com/t/ec2-exact-count-and-stopped-instances/17874/5 "2016-05-29T02:40:24Z")

</div>

I am still facing the same issue as mentioned by Steven Ringo in his original post above. The PR you mentioned below seems to solve the problem of starting or stopping instances based on tags, but not necessarily the issue originally described above.

I am using exact\_count option with ec2 module to ensure I have exactly 2 instances with specific tags. However, if one of the instances is in stopped state and the playbook is run again, it creates another instances as if the stopped instance does not even exist. Does anyone know if this is the expected behavior as of today?

I can’t use the state parameter when I use exact\_count parameter because it gives me the following error -  
_parameters are mutually exclusive: [‘exact\_count’, ‘state’])_

Can someone please guide me if I am looking at stale information or missing something?

Thanks,  
Rohit

---

<div class="post-metadata">

**Author:** ![Olivier\_Cervello](https://avatars.discourse-cdn.com/v4/letter/o/c68b51/32.png) [@Olivier\_Cervello](https://forum.ansible.com/u/Olivier_Cervello)\
**Post date:** [December 22, 2017, 6:57pm UTC](https://forum.ansible.com/t/ec2-exact-count-and-stopped-instances/17874/6 "2017-12-22T18:57:32Z")

</div>

This is biting me too.  
I’m trying to set the state: absent / present / stopped automatically but if exact\_count is set I’m not able too…  
It defeats the purpose of trying to act on multiple instances states.
