# Dynamic inventories, EC2 tags, and commas

**URL:** <https://forum.ansible.com/t/dynamic-inventories-ec2-tags-and-commas/19684>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [November 3, 2015, 5:41pm UTC](https://forum.ansible.com/t/dynamic-inventories-ec2-tags-and-commas/19684 "2015-11-03T17:41:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![H\_Wade\_Minter](https://avatars.discourse-cdn.com/v4/letter/h/f05b48/32.png) [@H\_Wade\_Minter](https://forum.ansible.com/u/H_Wade_Minter)\
**Post date:** [November 3, 2015, 5:41pm UTC](https://forum.ansible.com/t/dynamic-inventories-ec2-tags-and-commas/19684/1 "2015-11-03T17:41:39Z")

</div>

Hi all,

I’m managing some Ubuntu EC2 servers with Ansible - they primarily run applications that get deployed with Capistrano, via the cap-ec2 plugin ([https://github.com/forward3d/cap-ec2](https://github.com/forward3d/cap-ec2)). cap-ec2 looks for a “Roles” tag, featuring a comma-separated list of server roles (app, db, web, worker, etc). In the setup we’re using, one EC2 server can fill multiple roles, so it’s common to see the Roles tag with commas in it. It also uses a “Stages” tag, with values like “production” and “staging”, to indicate environment.

I’d also like to use the ec2.py dynamic inventory script to pull the hosts out of EC2, and run playbooks against our staging app servers, for example. However, it seems like ec2.py doesn’t play well with comma-separated tag values (turning them into underscores). So a server that has Roles: app,web, that will get turned into tag\_Roles\_app\_web, but another server that has Roles: app,worker would be tag\_Roles\_app\_worker.

So my questions for those wiser in dynamic inventory than I: is there a way that I can aggregate any Role that features “app” into an inventory group, using these existing Roles tags? Do I need to set additional tags like “App: true” so that it would turn into tag\_App\_true and use those instead? Use a bunch of the :children style tags like below?

[app:children]  
tag\_Roles\_app\_web  
tag\_Roles\_app\_worker

[tag\_Roles\_app\_web]  
[tag\_Roles\_app\_worker]

Any suggestions would be appreciated!

Thanks,  
Wade

---

<div class="post-metadata">

**Author:** ![alexey.vazhnov](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@alexey.vazhnov](https://forum.ansible.com/u/alexey.vazhnov)\
**Post date:** [November 5, 2015, 11:18am UTC](https://forum.ansible.com/t/dynamic-inventories-ec2-tags-and-commas/19684/2 "2015-11-05T11:18:56Z")

</div>

I use this:  
In playbook:

`
