# Ansible inventory organization

**URL:** <https://forum.ansible.com/t/ansible-inventory-organization/29974>\
**Category:** Ansible Project\
**Created:** [March 25, 2019, 12:20pm UTC](https://forum.ansible.com/t/ansible-inventory-organization/29974 "2019-03-25T12:20:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sascha\_Andres](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sascha_andres/32/3742_2.png) [@Sascha\_Andres](https://forum.ansible.com/u/Sascha_Andres)\
**Post date:** [March 25, 2019, 12:20pm UTC](https://forum.ansible.com/t/ansible-inventory-organization/29974/1 "2019-03-25T12:20:58Z")

</div>

Hi,

I have servers that are organized into environment (such as staging, production, test, etc.) and into function (www, db, etc)

My idea was to have a group ‘production’ with a list of servers, and a group www with a list of servers. Just like this:

production:  
hosts:  
servera  
serverb

test:  
hosts:  
serverc  
serverd

www:  
hosts:  
servera  
serverb  
serverc  
serverd

Not I want something like  
ansible-playbook --limit production,www

and I want it applied only to servera and serverb. Not sure how to get there. Can anyone give a hint?

Kind regards,  
Sascha

---

<div class="post-metadata">

**Author:** ![Sascha\_Andres](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sascha_andres/32/3742_2.png) [@Sascha\_Andres](https://forum.ansible.com/u/Sascha_Andres)\
**Post date:** [March 25, 2019, 12:24pm UTC](https://forum.ansible.com/t/ansible-inventory-organization/29974/2 "2019-03-25T12:24:44Z")

</div>

Hi,

maybe to be clearer: I want the intersection of production & www.

Kind regards,  
Sascha

---

<div class="post-metadata">

**Author:** ![Sudheer\_S1](https://avatars.discourse-cdn.com/v4/letter/s/e99b99/32.png) [@Sudheer\_S1](https://forum.ansible.com/u/Sudheer_S1)\
**Post date:** [March 25, 2019, 12:46pm UTC](https://forum.ansible.com/t/ansible-inventory-organization/29974/3 "2019-03-25T12:46:50Z")

</div>

I recommend this layout:

environments/production/hosts

environment/staging/hosts

environment/test/hosts

Each hosts file should have list of servers.

all:  
hosts:  
placeholder  
children:  
db:  
hosts:  
dbserver1

```
 www:

  hosts:

    wwwserver1

```

You could execute playbook like:  
ansible-playbook -i environments/production/ webservers.yml

---

<div class="post-metadata">

**Author:** ![S\_C\_Rigler](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@S\_C\_Rigler](https://forum.ansible.com/u/S_C_Rigler)\
**Post date:** [March 25, 2019, 12:47pm UTC](https://forum.ansible.com/t/ansible-inventory-organization/29974/4 "2019-03-25T12:47:06Z")

</div>

If you want an intersection, try:

ansible-playbook --limit production:\&www

Or if you just want to run on "servera" and "serverb", you can do it like this:

ansible-playbook --limit ~server[ab]

--Steve

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [March 25, 2019, 12:47pm UTC](https://forum.ansible.com/t/ansible-inventory-organization/29974/5 "2019-03-25T12:47:11Z")

</div>

[https://docs.ansible.com/ansible/latest/user\_guide/intro\_patterns.html](https://docs.ansible.com/ansible/latest/user_guide/intro_patterns.html)

---

<div class="post-metadata">

**Author:** ![Sascha\_Andres](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sascha_andres/32/3742_2.png) [@Sascha\_Andres](https://forum.ansible.com/u/Sascha_Andres)\
**Post date:** [March 25, 2019, 12:52pm UTC](https://forum.ansible.com/t/ansible-inventory-organization/29974/6 "2019-03-25T12:52:40Z")

</div>

Hi,

thanks Steve, this is what I was looking for. I have found intersection in the configs now.

Thanks again,  
Sascha
