如何更改 group_vars 和 host_vars 的路径? [英] How can I change the path of group_vars and host_vars?

查看:29
本文介绍了如何更改 group_vars 和 host_vars 的路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以通过修改ansible.cfg中的roles_path来改变角色的路径.但是文档似乎没有提到任何关于更改group_varshost_vars 的路径.

we can change the path of roles by modifying roles_path in ansible.cfg. But the document doesn't seems to mention anything about changing the path of group_vars and host_vars.

如何更改这些路径?

我会将与 ansible 相关的文件与 Rails 应用程序库集成.我想在单个目录下收集角色和 vars 目录,但将 hosts 文件和 ansible.cfg 留在顶级目录,以便顶级目录很容易看到,但我仍然可以运行 ansible-playbook 在顶级目录,无需移动到深层目录.

I will integrate the files related to ansible with rails app repsitory. I want to gather the roles and vars directory under single directory but leave hosts file and ansible.cfg at the top directory so that the top directory is easy to see and still I can run ansible-playbook at the top directory without moving to deep directory.

谢谢,提前.

推荐答案

您不能更改 host_varsgroup_vars 的路径.

You cannot change the path for host_vars nor group_vars.

这些路径总是相对于您的hostfile.您可以在 ansible 配置中设置标准主机文件:

Those paths are always relative to your hostfile. You can set a standard hostfile in your ansible config:

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

在这种情况下,您的默认 host_vars 位于

in this case your default host_vars are to be found at

/path/to/hostfile/host_vars/

您不妨使用多个主机文件,假设您有:

You might as well use multiple hostfiles, assume you got:

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

使用 host_vars

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

在这种情况下,您可以使用以下方法从任何地方调用 ansible:

In this case you might call ansible from anywhere using:

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

请记住:host_varsgroup_vars 与您的 inventory (hostfile) 相关,因此您可以更改您的 inventory 位置并将相应的 host_vars 放在其下方.

Just remember: the host_vars and group_vars are related to your inventory (hostfile) and therefore you can change your inventory location and put the according host_vars below it.

这篇关于如何更改 group_vars 和 host_vars 的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆