本文介绍了如何使本地角色与从ansible-galaxy加载的角色分开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我观察到从银河下载的角色安装在roles/目录中,该目录中已经有内部角色,很难区分外部角色和内部角色.

I observed that roles downloaded from galaxy get installed inside the roles/ directory, where we already have our in-house ones, making quite hard to distiguish between external ones and internal ones.

有没有办法将它们保存在单独的目录中,以便我们避免混乱?

Is there a way to keep them in separated directories, so we can avoid confusions?

在大多数情况下,我希望有一个脚本来更新银河星系,并且我们不会在内部对其进行修改.

In most cases I would expect to have a script that is updating the galaxy ones and that we would not modify them internally.

推荐答案

我认为没有标准的方法,但是您可以利用Ansibles的行为来发挥自己的优势.

I think there is no standard way of doing this but you can use Ansibles behavior to your advantage.

可以在两个位置搜索角色:

Ansible searches in two locations for roles:

  • 在相对于您的剧本的roles目录中
  • 您在ansible.cfg
  • 中配置的路径
  • In the roles directory relative to your playbook
  • The path you configured in your ansible.cfg

您现在需要做的取决于实际存储角色的位置.我们正在存储相对于剧本的角色,因此所有内容都在同一个git repo中.

What you now need to do depends on where you actually store you roles. We are storing our roles relative to our playbooks, so everything is in the same git repo.

现在,您可以ansible.cfg 中定义以查找另一个文件夹中的角色:

Now you could define in your ansible.cfg to look for roles in an additional folder:

roles_path=./galaxy_roles

ansible-galaxy默认情况下会将角色安装到roles_path的第一个找到的路径中,因此,如果您有多个角色路径,请确保首先添加galaxy文件夹.您不需要显式添加roles文件夹.默认情况下,Ansible将始终在相对于剧本的./roles文件夹中搜索角色.

ansible-galaxy will install roles by default into the first found path of roles_path, so make sure to add the galaxy folder as very first if you have multiple role paths. You do not need to add the roles folder explicitly. Ansible will by default always search for roles inside the ./roles folder relative to the playbook.

或者,您也可以指示星系安装到其他位置:

Alternatively you can also instruct galaxy to install to a different location:

ansible-galaxy install --roles-path=./galaxy_roles foo

这篇关于如何使本地角色与从ansible-galaxy加载的角色分开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 18:06