首页 文章

如何从其他角色指定Ansible Galaxy角色的依赖?

提问于
浏览
1

我通过在 meta/main.yml 中声明它来为我的角色指定依赖项 .

---
dependencies:
  - role: angstwad.docker_ubuntu
    src: https://github.com/angstwad/docker.ubuntu
    scm: git
    version: v2.3.0

但是,当我尝试执行Ansible playbook时,我看到错误消息:

ERROR! the role 'angstwad.docker_ubuntu' was not found in /home/.../ansible/roles:/etc/ansible/roles:/home/.../ansible/roles:/home/.../ansible

The error appears to have been in '/home/.../roles/docker-node/meta/main.yml': line 5, column 5, but may be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

  - role: angstwad.docker_ubuntu
    ^ here

从错误消息中我得出结论,即使在 docker-node/meta/main.yml 中明确提到外部角色 angstwad.docker_ubuntu ,也没有导入 .


我可以指定Ansible Galaxy的外部依赖项,即使我的角色本身尚未上传到Ansible Galaxy吗?

或者我是否需要使用 ansible-galaxy 显式导入它们?


来自Ansible documentation

角色也可以依赖于其他角色,当您安装具有依赖关系的角色时,将自动安装这些依赖关系 . 您可以通过提供角色列表在meta / main.yml文件中指定角色依赖项 . 如果角色的来源是Galaxy,则只需以username.role_name格式指定角色即可 . 还支持requirements.yml中使用的更复杂的格式,允许您提供src,scm,版本和名称 .

通过遵循另一个SO问题(How to automatically install Ansible Galaxy roles?)的建议,听起来需要手动或使用变通方法明确地下载外部依赖项 .

1 回答

  • 0

    根据documentation you linked,您会看到:

    当ansible-galaxy遇到依赖关系时,它会自动将每个依赖项安装到roles_path .

    下载依赖项仅由ansible-galaxy处理,src元信息没有看到相应的文件夹 - 它失败了 . 与answer in question you linked中一样,您确实可以创建第一个任务,或者在每个开始之前包含在您的剧本中以运行ansible galaxy .

相关问题