# EC2 Instance Creation.

**URL:** <https://forum.ansible.com/t/ec2-instance-creation/17896>\
**Category:** Ansible Project\
**Created:** [April 2, 2015, 8:59pm UTC](https://forum.ansible.com/t/ec2-instance-creation/17896 "2015-04-02T20:59:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nico\_K](https://avatars.discourse-cdn.com/v4/letter/n/46a35a/32.png) [@Nico\_K](https://forum.ansible.com/u/Nico_K)\
**Post date:** [April 2, 2015, 8:59pm UTC](https://forum.ansible.com/t/ec2-instance-creation/17896/1 "2015-04-02T20:59:52Z")

</div>

Hi,

I might be doing things backwards, but I’m gonna ask anyway.

In my scenario, I first add the host\_vars/new\_host and only then do I run the ec2 create task (which is delegated to localhost obviously).  
After the instance is created, all variables already exist since they are defined in host\_vars,so far so good.

The only problem with this approach is that it doesn’t seem to be re-entrant, since the ec2 task will create a new instance every single time it’s called.  
Is there a way to have the ‘ec2’ task only spawn the instance when it does not exist yet (for example based on it’s tags?)

Thanks,  
Nico.

---

<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:** [April 3, 2015, 6:22pm UTC](https://forum.ansible.com/t/ec2-instance-creation/17896/2 "2015-04-03T18:22:41Z")

</div>

Nico,

Please see: [http://docs.ansible.com/ec2\_module.html](http://docs.ansible.com/ec2_module.html)

Specifically the “count” and “count\_tag” options.

- James

---

<div class="post-metadata">

**Author:** ![Nico\_K](https://avatars.discourse-cdn.com/v4/letter/n/46a35a/32.png) [@Nico\_K](https://forum.ansible.com/u/Nico_K)\
**Post date:** [April 3, 2015, 8:39pm UTC](https://forum.ansible.com/t/ec2-instance-creation/17896/3 "2015-04-03T20:39:21Z")

</div>

Thanks James, I will say I misread what count\_tag did…  
I ended up writing myself a custom Library in the end though
