# howto use multiple environments with multiple groups?

**URL:** <https://forum.ansible.com/t/howto-use-multiple-environments-with-multiple-groups/16759>\
**Category:** Ansible Project\
**Created:** [November 12, 2014, 4:20pm UTC](https://forum.ansible.com/t/howto-use-multiple-environments-with-multiple-groups/16759 "2014-11-12T16:20:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tristan\_van\_Bokkem](https://avatars.discourse-cdn.com/v4/letter/t/ebca7d/32.png) [@Tristan\_van\_Bokkem](https://forum.ansible.com/u/Tristan_van_Bokkem)\
**Post date:** [November 12, 2014, 4:20pm UTC](https://forum.ansible.com/t/howto-use-multiple-environments-with-multiple-groups/16759/1 "2014-11-12T16:20:52Z")

</div>

Hi,

As explained here [http://docs.ansible.com/intro\_inventory.html#splitting-out-host-and-group-specific-data](http://docs.ansible.com/intro_inventory.html#splitting-out-host-and-group-specific-data) we are using multiple environments (acceptance / production) with ansible-playbooks and have set it up as follow:

deploy.yml  
inventory

> \_ inventory-production  
> \_inventory-acceptance  
> group\_vars/  
> \_ acceptance/group1  
> \_ acceptance/group2

> \_ production/group1  
> \_ production/group2

host\_vars/

> \_ host1.accept  
> \_ host2.accept

> \_ host1.prod  
> \_ host2.prod

…

We have for instance some iptables vars defined in group1 and group2. Each specific for their group of hosts.  
Now when we run the ansible playbook deploy.yml together with the inventory-production inventory it soon start to work on a host in group1. It will run the tasks for the iptables role and the taks will need vars from the group\_vars directory. However it seems it is using the vars that has been combined of both groups and it will use the vars which are alphabetical last. Which in this case is group2. So it is using the wrong vars.

Any idea why this is going wrong?

---

<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:** [November 17, 2014, 9:24pm UTC](https://forum.ansible.com/t/howto-use-multiple-environments-with-multiple-groups/16759/2 "2014-11-17T21:24:23Z")

</div>

This is a common misconception.

All groups that a host are in apply to the host during a run.

This is because groups may imply physical location, purpose, hardware type, and more, while you may only be selecting them by say, purpose.
