# Differentiating between environments using the ec2 dynamic inventory

**URL:** <https://forum.ansible.com/t/differentiating-between-environments-using-the-ec2-dynamic-inventory/22679>\
**Category:** Ansible Project\
**Created:** [September 29, 2016, 4:49pm UTC](https://forum.ansible.com/t/differentiating-between-environments-using-the-ec2-dynamic-inventory/22679 "2016-09-29T16:49:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![daniel\_robert\_pilch](https://avatars.discourse-cdn.com/v4/letter/d/d78d45/32.png) [@daniel\_robert\_pilch](https://forum.ansible.com/u/daniel_robert_pilch)\
**Post date:** [September 29, 2016, 4:49pm UTC](https://forum.ansible.com/t/differentiating-between-environments-using-the-ec2-dynamic-inventory/22679/1 "2016-09-29T16:49:06Z")

</div>

Hi all,

Suppose I have two environments and in EC2 built with cloudformation and they are grouped or tagged as:

tag\_aws\_cloudformation\_stack\_name\_example\_d1

tag\_aws\_cloudformation\_stack\_name\_example\_d2

within each cloudformation group I will have servers, they are tagged as follows:

ec2:  
Role=example\_ldap

Ansible:  
tag\_ec2\_Role=example\_ldap

I use a limit on my ansible play for one of the grouped environments:

-l tag\_aws\_cloudformation\_stack\_name\_example\_d2

When I run a play, and try to get the hosts of ‘example\_ldap’:

hostvars[groups[‘tag\_Role\_example\_ldap’][0]].ec2\_tag\_Name

I could receive either d1 or d2’s example\_ldap host.

Is there a way I can limit what I get back from the ec2 dynamic inventory or do I need to be more specific with my group names, so example\_ldap would become example\_ldap\_d1? Or am I missing out on a better way to achieve this?

Thanks
