# ec2.py groups

**URL:** <https://forum.ansible.com/t/ec2-py-groups/14315>\
**Category:** Ansible Project\
**Created:** [January 10, 2014, 6:10pm UTC](https://forum.ansible.com/t/ec2-py-groups/14315 "2014-01-10T18:10:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yves\_Dorfsman](https://avatars.discourse-cdn.com/v4/letter/y/9de0a6/32.png) [@Yves\_Dorfsman](https://forum.ansible.com/u/Yves_Dorfsman)\
**Post date:** [January 10, 2014, 6:10pm UTC](https://forum.ansible.com/t/ec2-py-groups/14315/1 "2014-01-10T18:10:24Z")

</div>

When using dynamic inventory, my understanding is that you group your hosts with EC2 tags. How do you add a host to two groups then, since EC2 can only take one value for a given key?

Example:  
text inventory:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[web]  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sever1  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;server2

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[app]  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;server1  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;server3

In EC2, I use a tag called 'group', but I can only have one value for that group, either web or app...

Anybody run into this issue?

Thanks.

---

<div class="post-metadata">

**Author:** ![Peter\_Gehres](https://avatars.discourse-cdn.com/v4/letter/p/f17d59/32.png) [@Peter\_Gehres](https://forum.ansible.com/u/Peter_Gehres)\
**Post date:** [January 10, 2014, 6:44pm UTC](https://forum.ansible.com/t/ec2-py-groups/14315/2 "2014-01-10T18:44:59Z")

</div>

You could invert the key:value paradigm for groups and make them: “web:group” and “app:group” which would yield tag\_web\_group and tag\_app\_group. It isn’t pretty but it would work.

---

<div class="post-metadata">

**Author:** ![Yves\_Dorfsman](https://avatars.discourse-cdn.com/v4/letter/y/9de0a6/32.png) [@Yves\_Dorfsman](https://forum.ansible.com/u/Yves_Dorfsman)\
**Post date:** [January 10, 2014, 8:58pm UTC](https://forum.ansible.com/t/ec2-py-groups/14315/3 "2014-01-10T20:58:10Z")

</div>

Yes I guess...

I'm a bit surprised and worried to only get one answer. Are there many people out there using the dynamic inventory with ec2.py (I like to use well tested, well used modules)?

Anybody else solved the issue of belonging to more than one group another way?

Thanks.

---

<div class="post-metadata">

**Author:** ![Peter\_Gehres](https://avatars.discourse-cdn.com/v4/letter/p/f17d59/32.png) [@Peter\_Gehres](https://forum.ansible.com/u/Peter_Gehres)\
**Post date:** [January 10, 2014, 9:55pm UTC](https://forum.ansible.com/t/ec2-py-groups/14315/4 "2014-01-10T21:55:07Z")

</div>

Well, from an ansible perspective, the way we do it is not by multiple groups. We use roles instead. So, for example, one of our “utility hosts” in ec2 is an ldap-slave, splunk forwarder, bastion host, etc. Instead of tagging each group we use tag\_aws\_utility and then run all of those roles in the playbook.

---

<div class="post-metadata">

**Author:** ![ghexsel](https://avatars.discourse-cdn.com/v4/letter/g/dbc845/32.png) [@ghexsel](https://forum.ansible.com/u/ghexsel)\
**Post date:** [April 11, 2014, 12:14am UTC](https://forum.ansible.com/t/ec2-py-groups/14315/5 "2014-04-11T00:14:39Z")

</div>

Sorry for necro-ing this.

We solved this by adding the whole pair to the tag key itself, so it creates groups like tag\_class\_database\_ (mapped from “class\_database”: “”).

Now you can add machines to multiple groups, filter machines that are in more than one class, etc.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [April 15, 2014, 9:04pm UTC](https://forum.ansible.com/t/ec2-py-groups/14315/6 "2014-04-15T21:04:06Z")

</div>

Nice solution!

---

<div class="post-metadata">

**Author:** ![Mike\_Trienis](https://avatars.discourse-cdn.com/v4/letter/m/22d042/32.png) [@Mike\_Trienis](https://forum.ansible.com/u/Mike_Trienis)\
**Post date:** [May 13, 2015, 4:10am UTC](https://forum.ansible.com/t/ec2-py-groups/14315/7 "2015-05-13T04:10:00Z")

</div>

Hi guys,

I have the exact same issue and can not seem to find an elegant solution.

Does anyone have a better solution than the inverted key value paradigm?

Also, has anyone manage to automate the route53 entries using the dynamic inventory file?

Thanks, Mike.
