# inventory\_dir is still present as a global variable in Ansible 2.4  ?

**URL:** <https://forum.ansible.com/t/inventory-dir-is-still-present-as-a-global-variable-in-ansible-2-4/26918>\
**Category:** Ansible Project\
**Created:** [March 7, 2018, 11:24am UTC](https://forum.ansible.com/t/inventory-dir-is-still-present-as-a-global-variable-in-ansible-2-4/26918 "2018-03-07T11:24:35Z")\
**Posts on this page:** 2\
**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:** [March 7, 2018, 11:24am UTC](https://forum.ansible.com/t/inventory-dir-is-still-present-as-a-global-variable-in-ansible-2-4/26918/1 "2018-03-07T11:24:35Z")

</div>

Hi All,

I am trying to understand the changes with Ansible 2.4 that affects the usage of inventory\_dir variable.

Earlier i was using a static host file and in my playbooks, i was heavily relying on inventory\_dir to load variable files which in turn was loading the target hosts. I understand the purpose of making the inventory\_dir as a hostvar, what i did not understand is **how can i still access inventory\_dir directly as a global variable in my playbooks**  **?**

To show what i mean, i created a little demo:

**hosts.info**

`

[locals]  
local1 localhost ansible\_connection=local  
local2 localhost ansible\_connection=local

`

**varsFile.yaml**

`

#This doesn’t work anymore  
#moreVars: “{{ inventory\_dir ~ ‘moreVars.yaml’ }}”

#This also works  
#moreVars: “{{hostvars[groups.all.0].inventory\_dir}}/moreVars.yaml”

#This works and this is what i was using before 2.4  
moreVars: “{{inventory\_dir}}/moreVars.yaml”

`

**moreVars.yaml**

`

#Prior to 2.4, this is how i defined target hosts. I understand this will not work anymore

targetHosts: locals

who: MORE\_VARS

`

**playbook.yaml**

`

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [March 7, 2018, 5:57pm UTC](https://forum.ansible.com/t/inventory-dir-is-still-present-as-a-global-variable-in-ansible-2-4/26918/2 "2018-03-07T17:57:44Z")

</div>

Please see [http://docs.ansible.com/ansible/latest/porting\_guide\_2.4.html#inventory](http://docs.ansible.com/ansible/latest/porting_guide_2.4.html#inventory) for information about the change to inventory\_dir
