# Playbook look for hosts file

**URL:** <https://forum.ansible.com/t/playbook-look-for-hosts-file/16957>\
**Category:** Ansible Project\
**Created:** [December 4, 2014, 5:10am UTC](https://forum.ansible.com/t/playbook-look-for-hosts-file/16957 "2014-12-04T05:10:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yvo](https://avatars.discourse-cdn.com/v4/letter/y/ea666f/32.png) [@Yvo](https://forum.ansible.com/u/Yvo)\
**Post date:** [December 4, 2014, 5:10am UTC](https://forum.ansible.com/t/playbook-look-for-hosts-file/16957/1 "2014-12-04T05:10:05Z")

</div>

Hi,

It seems common practice for playbooks to have a “hosts” file in the root of the playbook.  
When you run a playbook you have to supply it via the -i parameter, otherwise you will get the error: “ERROR: Unable to find an inventory file, specify one with -i ?”

It would be nice if Ansible would automaticly detect the hosts file in the playbook folder. Less arguments would make it even easier to use.

---

<div class="post-metadata">

**Author:** ![Tomasz\_Kontusz](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@Tomasz\_Kontusz](https://forum.ansible.com/u/Tomasz_Kontusz)\
**Post date:** [December 4, 2014, 5:37am UTC](https://forum.ansible.com/t/playbook-look-for-hosts-file/16957/2 "2014-12-04T05:37:46Z")

</div>

I think explicitly passing in the inventory is OK: pretty soon you’ll have at least two of them (staging/prod etc.), and you REALLY don’t want to apply changes to the wrong set of hosts 😉

If you still want to set a default inventory path, you can do this through ANSIBLE\_HOSTS environment variable or by setting “hostfile” in ansible.cfg

Yvo van Beek [yvo@codegazer.com](mailto:yvo@codegazer.com) napisał:

---

<div class="post-metadata">

**Author:** ![Yvo](https://avatars.discourse-cdn.com/v4/letter/y/ea666f/32.png) [@Yvo](https://forum.ansible.com/u/Yvo)\
**Post date:** [December 4, 2014, 10:15am UTC](https://forum.ansible.com/t/playbook-look-for-hosts-file/16957/3 "2014-12-04T10:15:35Z")

</div>

For staging you create a separate group in the same hostfile right?  
And you can’t name them both “hosts” :), so that shouldn’t be a problem.

---

<div class="post-metadata">

**Author:** ![Tomasz\_Kontusz](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@Tomasz\_Kontusz](https://forum.ansible.com/u/Tomasz_Kontusz)\
**Post date:** [December 4, 2014, 7:24pm UTC](https://forum.ansible.com/t/playbook-look-for-hosts-file/16957/4 "2014-12-04T19:24:58Z")

</div>

I’m using separate inventory for staging, to be extra sure those environments don’t mix. And it’s actually a pretty standard practice to do so.
