EC2 Instance Creation.

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.

Nico,

Please see: http://docs.ansible.com/ec2_module.html

Specifically the “count” and “count_tag” options.

  • James

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