# Working With Amazon AWS / EC2

**URL:** <https://forum.ansible.com/t/working-with-amazon-aws-ec2/11480>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [May 1, 2012, 6:51pm UTC](https://forum.ansible.com/t/working-with-amazon-aws-ec2/11480 "2012-05-01T18:51:38Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![CK1](https://avatars.discourse-cdn.com/v4/letter/c/fbc32d/32.png) [@CK1](https://forum.ansible.com/u/CK1)\
**Post date:** [May 1, 2012, 6:51pm UTC](https://forum.ansible.com/t/working-with-amazon-aws-ec2/11480/1 "2012-05-01T18:51:38Z")

</div>

Hi all,

I’m curious as to how you guys handle the issue with dynamic hosts such as the instances started up on AWS?

This is a similar issue I have with using Puppet. Chef tends to work better since there’s a way to designate roles using the startup data. But as Ansible uses a “static” hosts list or requires the use of an external hosts script (similar to Puppet), how do you guys deal with a newly started instance?

I would hate having to manually update the hosts file every time a new instance is started up.

Some ways that I’m thinking about:

1. an external hosts script that grabs a list of all instances via AWS API and use security groups as roles/classes.

2. Somehow have the startup data indicate the roles and have that file written to a file on the instance. However, how would Ansible go about retrieving this information in the first place?

3. Every instance that gets started publishes its role (via startup data or security group) and post it somewhere else such as a S3 bucket or via the use of some directory service.

Would appreciate your suggestions and thoughts.

Thanks,  
Chris

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [May 1, 2012, 7:05pm UTC](https://forum.ansible.com/t/working-with-amazon-aws-ec2/11480/2 "2012-05-01T19:05:47Z")

</div>

I’m assuming people will either do external hosts scripts or have something that generates their inventory.

The provisioning tool should probably write to something an external hosts script could read, unless you want to query AWS, which you could probably do as well.

---

<div class="post-metadata">

**Author:** ![Will\_Newby](https://avatars.discourse-cdn.com/v4/letter/w/a88e4f/32.png) [@Will\_Newby](https://forum.ansible.com/u/Will_Newby)\
**Post date:** [May 2, 2012, 4:31am UTC](https://forum.ansible.com/t/working-with-amazon-aws-ec2/11480/3 "2012-05-02T04:31:36Z")

</div>

Chris,

I’m planning on writing some scripts that query the bash util “ec2-describe-tags” and cross-referencing it with “ec2-describe-instances” and sort the output into a basic hosts file for Ansible. They probably won’t be extremely robust (mainly just tagging for role and environment), but I’ll try and post them here once they’re put together.

Cheers!

---

<div class="post-metadata">

**Author:** ![Peter\_Sankauskas](https://avatars.discourse-cdn.com/v4/letter/p/ea666f/32.png) [@Peter\_Sankauskas](https://forum.ansible.com/u/Peter_Sankauskas)\
**Post date:** [July 6, 2012, 8:18pm UTC](https://forum.ansible.com/t/working-with-amazon-aws-ec2/11480/4 "2012-07-06T20:18:43Z")

</div>

Hi Will,

Did you make any progress with this? Would love to see what you have built.

Peter

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [July 7, 2012, 12:09am UTC](https://forum.ansible.com/t/working-with-amazon-aws-ec2/11480/5 "2012-07-07T00:09:52Z")

</div>

> I use boto (run within fabric) for this purpose, which spins up instances and then writes a new hosts file with their addresses.

The fabric users mailing list is elsewhere 🙂

---

<div class="post-metadata">

**Author:** ![Rob\_Tirrell](https://avatars.discourse-cdn.com/v4/letter/r/3da27b/32.png) [@Rob\_Tirrell](https://forum.ansible.com/u/Rob_Tirrell)\
**Post date:** [July 7, 2012, 12:20am UTC](https://forum.ansible.com/t/working-with-amazon-aws-ec2/11480/6 "2012-07-07T00:20:01Z")

</div>

Well, I guess my suggestion was for Will: boto is (IME) probably going to be simpler than wrapping around the AWS CLI tools yourself.

---

<div class="post-metadata">

**Author:** ![Brad\_Olson](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@Brad\_Olson](https://forum.ansible.com/u/Brad_Olson)\
**Post date:** [July 17, 2012, 4:35pm UTC](https://forum.ansible.com/t/working-with-amazon-aws-ec2/11480/7 "2012-07-17T16:35:41Z")

</div>

I wrote a pretty simplistic external inventory script which I need to remove sensitive info from then can post.

---

<div class="post-metadata">

**Author:** ![Peter\_Sankauskas](https://avatars.discourse-cdn.com/v4/letter/p/ea666f/32.png) [@Peter\_Sankauskas](https://forum.ansible.com/u/Peter_Sankauskas)\
**Post date:** [July 17, 2012, 4:52pm UTC](https://forum.ansible.com/t/working-with-amazon-aws-ec2/11480/8 "2012-07-17T16:52:03Z")

</div>

As of yesterday, there is an external inventory script specifically for EC2 in the devel branch under examples/scripts. Please give it a try and post any feedback you have.

If you script does more than this, please feel free to add to it and post a PR.

I am working on the documentation for it as well, so that will be available shortly.

Peter
