# Looking for global level equivalent of 'inventory\_dir' with Ansible 2.4 onwards

**URL:** <https://forum.ansible.com/t/looking-for-global-level-equivalent-of-inventory-dir-with-ansible-2-4-onwards/26094>\
**Category:** Ansible Project\
**Created:** [November 21, 2017, 9:54am UTC](https://forum.ansible.com/t/looking-for-global-level-equivalent-of-inventory-dir-with-ansible-2-4-onwards/26094 "2017-11-21T09:54:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ishan\_jain](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@ishan\_jain](https://forum.ansible.com/u/ishan_jain)\
**Post date:** [November 21, 2017, 9:54am UTC](https://forum.ansible.com/t/looking-for-global-level-equivalent-of-inventory-dir-with-ansible-2-4-onwards/26094/1 "2017-11-21T09:54:09Z")

</div>

Hi all,

I have a bunch of playbooks which only define what needs to be done, and i had split my inventory in some logical groups, so each inventory file is a complete definition of this group and to run run any playbook, i would simply use the desired inventory file.

The hosts part of my playbook is defined by a variable and this variable is defined by a file which i will always find next to any of my inventory. So i would simply load this file in my playbooks like this:

`  
vars\_file

- “{{inventory\_dir}}/host\_definition.yaml”  
`

It worked perfectly fine till now, but i see that this is going to break in Ansible 2.4 as **inventory\_dir** is now a host var so i cannot use it to load host variables.  
So my questions:

1. Any alternative to get path of inventory file at the global level ?
2. I want to keep the target host list defined (and thus loaded with) in the inventory. I understand the whole situation where Ansible needs to know the host vars before loading the variables within, but i would like to load a global variable from within inventory files. Is this possible ?

Note: In the release notes of Ansible 2.4 ( [https://github.com/ansible/ansible/blob/stable-2.4/CHANGELOG.md#24-dancing-days---2017-09-19](https://github.com/ansible/ansible/blob/stable-2.4/CHANGELOG.md#24-dancing-days---2017-09-19) ) there is a mention about change in **include\_dir** which i think should be **inventory\_dir**

The `include_dir` var is not a global anymore, as we now allow multiple inventory sources, it is now host dependant. This means it cannot be used wherever host vars are not permitted, for example in task/handler names.

---

<div class="post-metadata">

**Author:** ![Anthony\_Truskinger](https://avatars.discourse-cdn.com/v4/letter/a/bc79bd/32.png) [@Anthony\_Truskinger](https://forum.ansible.com/u/Anthony_Truskinger)\
**Post date:** [May 16, 2019, 5:38am UTC](https://forum.ansible.com/t/looking-for-global-level-equivalent-of-inventory-dir-with-ansible-2-4-onwards/26094/2 "2019-05-16T05:38:15Z")

</div>

Did you ever find a solution to this?

---

<div class="post-metadata">

**Author:** ![ishan\_jain](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@ishan\_jain](https://forum.ansible.com/u/ishan_jain)\
**Post date:** [May 16, 2019, 7:34am UTC](https://forum.ansible.com/t/looking-for-global-level-equivalent-of-inventory-dir-with-ansible-2-4-onwards/26094/3 "2019-05-16T07:34:29Z")

</div>

Yes, we did, as this was the structure of every single playbook in our project. But to be honest, i am blanking out on the solution that we did. Since I moved to another company last year, i don’t have access to the code base any more ☹  
I will try to stress my memory to blurt out the solution.

BR,  
Ishan

---

<div class="post-metadata">

**Author:** ![Anthony\_Truskinger](https://avatars.discourse-cdn.com/v4/letter/a/bc79bd/32.png) [@Anthony\_Truskinger](https://forum.ansible.com/u/Anthony_Truskinger)\
**Post date:** [May 17, 2019, 12:38am UTC](https://forum.ansible.com/t/looking-for-global-level-equivalent-of-inventory-dir-with-ansible-2-4-onwards/26094/4 "2019-05-17T00:38:44Z")

</div>

Thank you so much for the response - I appreciate it.

For other weary internet travellers, I went with the annoying, but simplest change, of explicitly defining localhost in every one of my inventories:

ungrouped:  
hosts:

# defined explicitly so {{ inventory\_dir }} will be defined

localhost:  
vars:  
ansible\_connection: local  
ansible\_python\_interpreter: “{{ansible\_playbook\_python}}”

And coupled that with this assertion where needed:

tasks:

- name: Check that inventory\_dir is defined for localhost  
assert:  
fail\_msg: “inventory\_dir was none, make sure you have localhost defined in your inventory”  
that:
- “inventory\_dir is defined”

–Anthony
