# read host from another inventory file

**URL:** <https://forum.ansible.com/t/read-host-from-another-inventory-file/19678>\
**Category:** Ansible Developer\
**Created:** [November 3, 2015, 3:28am UTC](https://forum.ansible.com/t/read-host-from-another-inventory-file/19678 "2015-11-03T03:28:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Agan\_Vikry](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@Agan\_Vikry](https://forum.ansible.com/u/Agan_Vikry)\
**Post date:** [November 3, 2015, 3:28am UTC](https://forum.ansible.com/t/read-host-from-another-inventory-file/19678/1 "2015-11-03T03:28:38Z")

</div>

I have two inventory files, staging and production.

staging contents:

```auto
[server]
192.168.56.101 #server 1
192.168.56.103 #server 2

```

production contents:

```auto
[server]
192.168.56.108 #server test

```

---

<div class="post-metadata">

**Author:** ![Dann\_Bohn](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@Dann\_Bohn](https://forum.ansible.com/u/Dann_Bohn)\
**Post date:** [November 3, 2015, 1:25pm UTC](https://forum.ansible.com/t/read-host-from-another-inventory-file/19678/2 "2015-11-03T13:25:16Z")

</div>

You can put both staging and production inventories in a folder, inventory, and call ansible-playbook -i inventory/ and both sets of hosts will be available to you.

If you use hosts: all anywhere in your playbook, this might not work, since it will target both environments. In that case I do hosts: “{{hosts}}” and specify the target on the command line

ansible-playbook - inventory/ -e hosts=staging

---

<div class="post-metadata">

**Author:** ![Agan\_Vikry](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@Agan\_Vikry](https://forum.ansible.com/u/Agan_Vikry)\
**Post date:** [November 4, 2015, 3:06am UTC](https://forum.ansible.com/t/read-host-from-another-inventory-file/19678/3 "2015-11-04T03:06:33Z")

</div>

I changed the structure by following this [tutorial](http://toja.io/using-host-and-group-vars-files-in-ansible/) , because I need staging and production have different database configuration. I still had the same issue with it.  
new structure :

> roles  
> production  
> –|group\_vars  
> ----|server.yml  
> –|inventory  
> staging

–|group\_vars  
----|server.yml  
–|inventory
