# Inventory folder structure verification

**URL:** <https://forum.ansible.com/t/inventory-folder-structure-verification/25783>\
**Category:** Ansible Project\
**Created:** [October 19, 2017, 9:33pm UTC](https://forum.ansible.com/t/inventory-folder-structure-verification/25783 "2017-10-19T21:33:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![john.laham](https://avatars.discourse-cdn.com/v4/letter/j/67e7ee/32.png) [@john.laham](https://forum.ansible.com/u/john.laham)\
**Post date:** [October 19, 2017, 9:33pm UTC](https://forum.ansible.com/t/inventory-folder-structure-verification/25783/1 "2017-10-19T21:33:15Z")

</div>

Hi all, first time posting, so apologies if I miss something.

I’m working on organizing an inventory folder for a multistage environment and would like verification on whether the way I expect to work is true, or if I’m missing something.

**Objective**  
Using the following inventory folder structure:

.  
├── production/  
│ ├── group\_vars/  
│ ├── host\_vars/  
│ │ └── hostname-prod.fqdn.yml  
│ └── inventory.ini # (_contains entry for hostname-prod.fqdn_)  
│  
├── staging/  
│ ├── group\_vars/  
│ ├── host\_vars/  
│ │ └── hostname-stage.fqdn.yml  
│ └── inventory.ini # (_contains entry for hostname-stage.fqdn_)  
│  
└── testing/  
├── group\_vars/  
├── host\_vars/  
│ └── hostname-test.fqdn.yml  
└── inventory.ini # (_contains entry for hostname-test.fqdn_)

I would execute a playbook (with “hosts: hostname-prod.fqdn”) to be run as follows, with the expectation that it will automatically pick up the hostname entry from the “production/inventory.ini” and the associated host variables from the “production/host\_vars/hostname-stage.fqdn.yml” file:

$\> ansible-playbook my-play.yml

**Problem**  
When I try to do this, the hostname entry is indeed picked up from the “production/inventory.ini” file, however, the associated host variables aren’t picked up from the “production/host\_vars/hostname-stage.fqdn.yml” file.

If I run the command as follows though, it does work:

$\> ansible-playbook -i production my-play.yml

**Question**  
Is this the correct and expected behavior? Or should my original method work without specifying “-i production”?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [December 11, 2018, 6:43pm UTC](https://forum.ansible.com/t/inventory-folder-structure-verification/25783/2 "2018-12-11T18:43:11Z")

</div>

Im unsure of what the problem is since you seem to have contradictory  
expectations, you state info should be picked from  
`"production/host_vars/hostname-stage.fqdn.yml` but that file is not  
under production, but under staging.

In any case you can use `ansible-inventory` to see what ansible  
actually composes from the given inventory.

---

<div class="post-metadata">

**Author:** ![Tchia04](https://avatars.discourse-cdn.com/v4/letter/t/fbc32d/32.png) [@Tchia04](https://forum.ansible.com/u/Tchia04)\
**Post date:** [December 14, 2018, 4:06am UTC](https://forum.ansible.com/t/inventory-folder-structure-verification/25783/3 "2018-12-14T04:06:53Z")

</div>

That is expected.

If you don’t specify -i how the ansible-playbook know you want to run against production or staging or test env ?

You could probably set some defaults using the inventory setting under defaults section in ansible.cfg. For example  
[https://raw.githubusercontent.com/ansible/ansible/devel/examples/ansible.cfg](https://raw.githubusercontent.com/ansible/ansible/devel/examples/ansible.cfg)

I would probably organize all the inventories in one folder by moving the production, staging and test folder under an inventory folder

Then you should be able to run  
Ansible-playbook -i inventory/production my-play.yml and pick up the grou\_vars and host\_vars

---

<div class="post-metadata">

**Author:** ![Alb0t](https://avatars.discourse-cdn.com/v4/letter/a/9fc348/32.png) [@Alb0t](https://forum.ansible.com/u/Alb0t)\
**Post date:** [December 14, 2018, 4:54am UTC](https://forum.ansible.com/t/inventory-folder-structure-verification/25783/4 "2018-12-14T04:54:00Z")

</div>

The behavior is the same if I specify -i ec2.py. I like to specify inventory manually instead of making it a global setting. Are you saying the yml should call the python script?
