How to change the path for group_vars and host_vars?

we can change the roles path by changing roles_path in ansible.cfg . But the document does not seem to say anything about changing the path of group_vars and host_vars .

How can I change these paths?

I will integrate files related to the ability to use the reils repository. I want to collect the roles and the vars directory in a single directory, but leave the hosts and ansible.cfg file in the upper directory, so that the upper directory is easy to see, and yet I can run ansible-playbook in the upper directory without going into a deep directory.

Thanks in advance.

+7
ansible
source share
1 answer

You cannot change the path for host_vars and group_vars .

These paths always apply to your hostfile . You can install the standard host file in your indispensable configuration:

 hostfile = /path/to/hostfile/hostfile.ini 

in this case your default host_vars is in

 /path/to/hostfile/host_vars/ 

You can also use multiple host files, assuming you have:

 /path/to/your/project/inventory/inventory.ini 

from host_vars to

 /path/to/your/project/inventory/host_vars/ 

In this case, you can call the opportunity anywhere using:

 ansible -i /path/to/your/project/inventory/inventory.ini my_playbook.yml 

Just remember: host_vars and group_vars are associated with your inventory (hostfile) and so you can change the location of inventory and put below host_vars below.

+9
source share

All Articles