[FEATURE REQUEST] Custom path for group_vars and host_vars in ansible.cfg

1,061 views
Skip to first unread message

muff...@gmail.com

unread,
Feb 10, 2016, 9:56:31 PM2/10/16
to Ansible Development
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 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

Mark Kusch

unread,
Feb 11, 2016, 1:26:58 AM2/11/16
to muff...@gmail.com, Ansible Development
+

Waiting for it since I'm using Ansible (which is quite some time).

# kraM
> --
> You received this message because you are subscribed to the Google Groups "Ansible Development" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ansible-deve...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.


--
kraM

Think can be useful if someone is needing some thinking about something.

gpg --recv-keys 0x6C215719
signature.asc

Marc Petrivelli

unread,
Feb 11, 2016, 12:28:14 PM2/11/16
to Ansible Development
+

I agree this would be a nice feature.  Forcing group_vars and host_vars to be relative to your inventory file/script was shorted sighted.  It's super sloppy but you can work around this with sym links.  Shamefully, I have done this.

Rahul Raj Purohit (RRP)

unread,
Jul 26, 2024, 9:47:33 AM (23 hours ago) Jul 26
to Ansible Development
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

Brian Coca

unread,
Jul 26, 2024, 9:50:37 AM (23 hours ago) Jul 26
to Ansible Development
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.
You can even disable the one shipped with core in favor of your own.
--
----------
Brian Coca (he/him/yo)

Reply all
Reply to author
Forward
0 new messages