我可以在私人 git 存储库中添加角色作为 Ansible 中的元/依赖项吗?

Sal*_*ley 3 ansible

我有一堆想要重用的 Ansible 角色。它们每个都保存在私有 BitBucket 中的一个 repo 中。

我想为我正在处理的角色添加托管在 Git 中的项目作为元/依赖项,但我不太清楚语法是什么。

在这个非工作示例中,一个角色需要在运行之前先使用参数部署另一个角色。

仅供参考,远程角色“acm_layout”旨在为服务器创建标准目录布局,以便我的角色可以在知道所有标准目录已经存在的情况下运行。

---
dependencies:
   - { role: project_keys } # Works fine, just reuses a local role

   - name: acm_layout # Doesn't work, but this is what I want to fix
     src: ssh://git@bigcompany.com/acm/acm_layout.git
     scm: git
     version: feature/initialize
     application_storage_dir: "{{base_storage_dir}}"
     application_data_dir: "{{app_data_dir}}"
Run Code Online (Sandbox Code Playgroud)

当我运行这个时,我收到以下错误:

ERROR! the role 'acm_layout' was not found in [lots of paths deleted]

The error appears to have been in '/home/zs5fgzg/_tmp/horizon_deployment_scf/ansible/roles/horizon_layout/meta/main.yaml': line 4, column 6, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

   - { role: horizon_keys }
   - src: ssh://git@bigcompany.com:7999/acm/acm_layout.git
     ^ here
Run Code Online (Sandbox Code Playgroud)

那么这样做的正确方法是什么?

小智 5

是的,您可以使用ansible-galaxy带有requirements.yml选项的安装来远程获取角色。创建requirements.yml如下:

并运行以下命令:

$ ansible-galaxy install -r requirements.yml -p roles/
Run Code Online (Sandbox Code Playgroud)

有关如何使用 ansible-galaxy 获取角色的更多信息,请访问 http://docs.ansible.com/ansible/latest/galaxy.html