# Can I define my inventory in my playbook directory?

**URL:** <https://forum.ansible.com/t/can-i-define-my-inventory-in-my-playbook-directory/22370>\
**Category:** Ansible Project\
**Tags:** windows\
**Created:** [August 24, 2016, 3:02pm UTC](https://forum.ansible.com/t/can-i-define-my-inventory-in-my-playbook-directory/22370 "2016-08-24T15:02:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jonathan\_Anderson](https://avatars.discourse-cdn.com/v4/letter/j/45deac/32.png) [@Jonathan\_Anderson](https://forum.ansible.com/u/Jonathan_Anderson)\
**Post date:** [August 24, 2016, 3:02pm UTC](https://forum.ansible.com/t/can-i-define-my-inventory-in-my-playbook-directory/22370/1 "2016-08-24T15:02:37Z")

</div>

Management Node:

- CentOs 6

- Ansible 2.1

Remote Node:

- Windows 7

- Powershell 3.0

My playbooks are all saved in /home/username/playbooks.

My inventory file is saved as /etc/ansible/hosts.

And I also use the file etc/ansible/group\_vars/windows.yml

I find it a hassle to go back and forth between these 2 locations. Why can’t I define my inventory and group vars in my playbooks directory? What is the best way to do that?

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [August 24, 2016, 3:08pm UTC](https://forum.ansible.com/t/can-i-define-my-inventory-in-my-playbook-directory/22370/2 "2016-08-24T15:08:11Z")

</div>

inventory can be anywhere you want, it just defaults to /etc/ansible/hosts, you can set in ansible.cfg or on the command line with -i switch. group/host\_vars just need to be in the same directory your inventory files are.

---

<div class="post-metadata">

**Author:** ![Jonathan\_Anderson](https://avatars.discourse-cdn.com/v4/letter/j/45deac/32.png) [@Jonathan\_Anderson](https://forum.ansible.com/u/Jonathan_Anderson)\
**Post date:** [August 31, 2016, 5:13pm UTC](https://forum.ansible.com/t/can-i-define-my-inventory-in-my-playbook-directory/22370/3 "2016-08-31T17:13:23Z")

</div>

I must be missing something. I created a ansible.cfg file with this…

[default]  
hostfile = /fs01/home/janderson/hosts

and one with this…

[default]  
inventory = /fs01/home/janderson/hosts

and neither one worked.

Where can I get a default or sample ansible.cfg file to modify?

---

<div class="post-metadata">

**Author:** ![Dick\_Davies](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Dick\_Davies](https://forum.ansible.com/u/Dick_Davies)\
**Post date:** [August 31, 2016, 5:29pm UTC](https://forum.ansible.com/t/can-i-define-my-inventory-in-my-playbook-directory/22370/4 "2016-08-31T17:29:17Z")

</div>

We lay ours out in the playbook directory like this

site.yml  
prod/  
&nbsp;&nbsp;&nbsp;&nbsp;- group\_vars/  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- all  
&nbsp;&nbsp;&nbsp;&nbsp;- hosts  
staging/  
&nbsp;&nbsp;&nbsp;- group\_vars/  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- all  
&nbsp;&nbsp;&nbsp;- hosts

and then run with

&nbsp;&nbsp;&nbsp;&nbsp;ansible-playbook -i $environment site.yml

---

<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:** [August 31, 2016, 6:22pm UTC](https://forum.ansible.com/t/can-i-define-my-inventory-in-my-playbook-directory/22370/5 "2016-08-31T18:22:18Z")

</div>

This last one is almost correct, but you are missing an s it's [defaults]

---

<div class="post-metadata">

**Author:** ![Jonathan\_Anderson](https://avatars.discourse-cdn.com/v4/letter/j/45deac/32.png) [@Jonathan\_Anderson](https://forum.ansible.com/u/Jonathan_Anderson)\
**Post date:** [August 31, 2016, 6:42pm UTC](https://forum.ansible.com/t/can-i-define-my-inventory-in-my-playbook-directory/22370/6 "2016-08-31T18:42:02Z")

</div>

Thanks Kai for pointing out my mistake!!
