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

问题描述

我观察到从 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 在两个位置搜索角色:

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 存储库中.

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 的第一个找到的路径中,因此如果您有多个角色路径,请确保首先添加星系文件夹.您不需要显式添加 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.

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

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