# group\_vars by multiple criteria

**URL:** <https://forum.ansible.com/t/group-vars-by-multiple-criteria/17279>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [January 15, 2015, 4:10pm UTC](https://forum.ansible.com/t/group-vars-by-multiple-criteria/17279 "2015-01-15T16:10:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brian\_N](https://avatars.discourse-cdn.com/v4/letter/b/5fc32e/32.png) [@Brian\_N](https://forum.ansible.com/u/Brian_N)\
**Post date:** [January 15, 2015, 4:10pm UTC](https://forum.ansible.com/t/group-vars-by-multiple-criteria/17279/1 "2015-01-15T16:10:59Z")

</div>

Hello. I have an interesting scenario that I have been pondering and would like some input from the community. I would like to apply group\_vars to series of servers, that are defined by application **roles** and also defined by the **environments** production and pre-producution, So the filter order should be: **role** → **environment**

I am using dynamic inventory, in specific, AWS.

The following tags are used:

- tag\_environment\_prod

- tag\_environment\_preprod

- tag\_role\_app1

- tag\_role\_app2  
EC2 instances would be tagged the following way:

preprod-app1: tag\_environment\_preprod, tag\_role\_app1  
preprod-app2: tag\_environment\_preprod, tag\_role\_app2

prod-app1 :tag\_environment\_prod, tag\_role\_app1  
Etc…

Regardless of the **role** assigned to that server, it shares a common configuration file:

#app.conf  
APP\_KEY={{ app\_key }}  
APP\_THING1={{ app\_thing1 }}  
APP\_THING2={{ app\_thing2 }}

My goal is to first filter groups based upon role, then based upon environment. Maybe something like:

/group\_vars  
/app1\_prod  
/app1\_preprod  
/app2\_prod  
/app2\_preprod

Using a dynamic inventory, how can I accomplish this filter using more than one EC2 tag?

Thanks!  
Brian
