ec2.py groups

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:

     [web]
     sever1
     server2

     [app]
     server1
     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.

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.

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.

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.

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.

Nice solution!

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.