ec2 exact_count and stopped instances

389 views
Skip to first unread message

Steven Ringo

unread,
Mar 30, 2015, 7:53:27 PM3/30/15
to ansible...@googlegroups.com

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

Majid al-Dosari

unread,
Aug 26, 2015, 9:43:34 AM8/26/15
to Ansible Project
i agree. this bothers me too.

Majid al-Dosari

unread,
Aug 27, 2015, 8:56:35 AM8/27/15
to Ansible Project

Greg DeKoenigsberg

unread,
Aug 27, 2015, 10:09:03 AM8/27/15
to Ansible Project
On Thu, Aug 27, 2015 at 8:56 AM, Majid al-Dosari
<majid.a...@gmail.com> wrote:
> aha 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

--g
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/a3dab1c5-8156-405e-86d1-36209c1fea0a%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



--
Greg DeKoenigsberg
Ansible Community Guy

Find out why SD Times named Ansible
their #1 Company to Watch in 2015:
http://sdtimes.com/companies-watch-2015/

Rohit Kothari

unread,
May 29, 2016, 11:42:50 AM5/29/16
to Ansible Project
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

Olivier Cervello

unread,
Dec 22, 2017, 1:57:32 PM12/22/17
to Ansible Project
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.
Reply all
Reply to author
Forward
0 new messages