# \[FEATURE REQUEST\] Custom path for group\_vars and host\_vars in ansible.cfg

**URL:** <https://forum.ansible.com/t/feature-request-custom-path-for-group-vars-and-host-vars-in-ansible-cfg/20527>\
**Category:** Ansible Developer\
**Created:** [February 11, 2016, 2:56am UTC](https://forum.ansible.com/t/feature-request-custom-path-for-group-vars-and-host-vars-in-ansible-cfg/20527 "2016-02-11T02:56:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![muffinsk](https://avatars.discourse-cdn.com/v4/letter/m/858c86/32.png) [@muffinsk](https://forum.ansible.com/u/muffinsk)\
**Post date:** [February 11, 2016, 2:56am UTC](https://forum.ansible.com/t/feature-request-custom-path-for-group-vars-and-host-vars-in-ansible-cfg/20527/1 "2016-02-11T02:56:31Z")

</div>

Hi all,

I’ve been wondering on how am I going to move the contents of my group\_vars and host\_vars to a different location then I found [https://github.com/ansible/ansible/issues/13051](https://github.com/ansible/ansible/issues/13051) which basically was rejected.

My use case is mainly to have a better organization of my configurations. Since I was able to specify a custom location for my inventory and roles\_path as stated also in the above link, I also wanted to set a custom location for my group\_vars and host\_vars.

Currently, my Ansible directory tree looks like this:

ANSIBLE\_DIR=/etc/ansible

$ANSIBLE\_DIR/ansible.cfg  
$ANSIBLE\_DIR/main.yml  
$ANSIBLE\_DIR/environment/{development,staging,production}  
$ANSIBLE\_DIR/roles/{defaults,files,handlers,meta,tasks,templates,vars}/

Then, I want to have my group\_vars and host\_vars to be located at:

$ANSIBLE\_DIR/vars/{groups,hosts}/

I find it messy (sorry) if my group\_vars and host\_vars are located inside the $ANSIBLE\_DIR/environment/ directory. Thus, I want to move it to some other place.

Thank you and I hope you will consider this feature request.

Kind regards,

Muffin

---

<div class="post-metadata">

**Author:** ![mark.kusch](https://avatars.discourse-cdn.com/v4/letter/m/8e8cbc/32.png) [@mark.kusch](https://forum.ansible.com/u/mark.kusch)\
**Post date:** [February 11, 2016, 6:26am UTC](https://forum.ansible.com/t/feature-request-custom-path-for-group-vars-and-host-vars-in-ansible-cfg/20527/2 "2016-02-11T06:26:51Z")

</div>



---

<div class="post-metadata">

**Author:** ![marc.petrivelli](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/marc.petrivelli/32/3773_2.png) [@marc.petrivelli](https://forum.ansible.com/u/marc.petrivelli)\
**Post date:** [February 11, 2016, 5:28pm UTC](https://forum.ansible.com/t/feature-request-custom-path-for-group-vars-and-host-vars-in-ansible-cfg/20527/3 "2016-02-11T17:28:13Z")

</div>



---

<div class="post-metadata">

**Author:** ![Rahul\_Raj\_Purohit\_RR](https://avatars.discourse-cdn.com/v4/letter/r/b77776/32.png) [@Rahul\_Raj\_Purohit\_RR](https://forum.ansible.com/u/Rahul_Raj_Purohit_RR)\
**Post date:** [July 26, 2024, 2:22am UTC](https://forum.ansible.com/t/feature-request-custom-path-for-group-vars-and-host-vars-in-ansible-cfg/20527/4 "2024-07-26T02:22:24Z")

</div>

Hi All,  
As much as I hate to bring an old thread back to life, I have to as I’ve failed to find workarounds for this issue.  
Based on my inventory file, I would like to keep the group\_vars dir in multiple locations instead of the same single directory as it makes it harder to maintain.  
So instead of

group\_vars  
├── db\_in  
├── db\_servers  
├── db\_us  
├── in\_servers  
├── us\_servers  
├── web\_in  
├── web\_servers  
└── web\_us

I would like to have something like (or any other suggestions/workaround to make things more organised) below:

group\_variables  
├── db-servers-grp  
│ ├── db\_in  
│ └── db\_us  
├── general-grp  
│ ├── db\_servers  
│ └── web\_servers  
├── region-grp  
│ ├── in\_servers  
│ └── us\_servers  
└── web-server-grp  
├── web\_in  
└── web\_us

This way I can have in my ansible.cfg file the following variable:

group\_vars\_dirs = group\_variables/db-servers-grp, group\_variables/general-grp, group\_variables/region-grp, group\_variables/web-server-grp

This would help in scalability when there are thousands of regions or even sub-regions  
I have an inventory as below (This is a sample of a larger inventory of around 2000 hosts):

all:  
children:  
web\_servers:  
children:  
web\_us:  
hosts:  
web\_us\_example1:  
web\_us\_example2:  
web\_us\_example3:  
web\_in:  
hosts:  
web\_in\_example1:  
web\_in\_example2:  
web\_in\_example3:  
db\_servers:  
children:  
db\_us:  
hosts:  
db\_us\_example1:  
db\_us\_example2:  
db\_us\_example3:  
db\_in:  
hosts:  
db\_in\_example1:  
db\_in\_example2:  
db\_in\_example3:  
us\_servers:  
children:  
web\_us:  
db\_us:  
in\_servers:  
children:  
web\_in:  
db\_in:

I would appreciate any feedback at all.

Thanks,  
Rahul Raj Purohit

---

<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:** [July 26, 2024, 1:50pm UTC](https://forum.ansible.com/t/feature-request-custom-path-for-group-vars-and-host-vars-in-ansible-cfg/20527/5 "2024-07-26T13:50:17Z")

</div>

You can just develop your own "vars plugin" that does this, the  
current host\_vars/group\_vars is implemented via the host\_group\_vars  
plugin included in core  
[https://docs.ansible.com/ansible/latest/collections/ansible/builtin/host\_group\_vars\_vars.html](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/host_group_vars_vars.html).  
You can even disable the one shipped with core in favor of your own.
