使用私有git角色依赖的Ansible playbook

9
我遇到了一个问题,无法运行带有一组私有角色的 Ansible playbook(即,存储在私有 Git 仓库中的 Ansible 角色)。
例如,我有一个 playbook 使用了名为 base 的角色,它依赖于 dep 角色,这两个角色都存储在私有 git 仓库中。运行 ansible-galaxy 可以正确地提取和安装所有角色和依赖项,但之后 ansible-playbook 却无法使用正确的角色名称。 play.yml
- hosts: test
  roles:
    - role: base

requirements.yml

- name: base
  src: ssh://git@10.0.0.1/ansible/role-base.git
  scm: git

role-base/meta/main.yml

galaxy-info:
  author: Me
  description: Test Ansible role dependencies
  min_ansible_version: 1.9
  platforms: Ubuntu
dependencies:
  - name: dep
    src: ssh://git@10.0.0.1/ansible/role-dep.git
    scm: git

$ ansible-galaxy -r requirements.yml
- executing: git clone ssh://git@10.0.0.1/ansible/role-base.git base
- executing: git archive --prefix=base/ --output=/tmp/tmp4YKG7a.tar
- extracting base to ansible-roles/base
- base was installed successfully
- adding dependency: dep
- executing: git clone ssh://git@10.0.0.1/ansible/role-dep.git dep
- executing: git archive --prefix=dep/ --output=/tmp/tmpT2YiW4.tar
- extracting base to ansible-roles/dep
- dep was installed successfully

$ ansible-playbook play.yml
ERROR: expected a role name in dictionary: {'scm': 'git', 'src': 'ssh://git@10.0.0.1/ansible/role-dep.git', 'name': 'dep'}

我尝试使用替代角色名称系统作为依赖项:

dependencies:
  - role: "git+ssh://git@10.0.0.1/ansible/role-dep.git,,dep"

这对于ansible-galaxy来说是可以接受的,但是ansible-playbook仍然失败了...

$ ansible-galaxy -r requirements.yml
- executing: git clone ssh://git@10.0.0.1/ansible/role-base.git base
- executing: git archive --prefix=base/ --output=/tmp/tmpTcvpDu.tar
- extracting base to ansible-roles/base
- base was installed successfully
- adding dependency: dep
- executing: git clone ssh://git@10.0.0.1/ansible/role-dep.git dep
- executing: git archive --prefix=dep/ --output=/tmp/tmpd726OV.tar
- extracting base to ansible-roles/dep
- dep was installed successfully

$ ansible-playbook play.yml
ERROR: cannot find role in <pwd>/roles/git+ssh://git@10.0.0.1/ansible/role-dep.git,,dep or <pwd>/git+ssh://git@10.0.0.1/ansible/role-dep.git,,dep or <pwd>/ansible-roles/git+ssh://git@10.0.0.1/ansible/role-dep.git,,dep

有没有一种正确使用私有仓库中角色依赖的方法?
2个回答

2

现在已经发布了1.9.5版。尽管我无法在发布说明中看到您的修复:https://groups.google.com/forum/#!topic/ansible-announce/h6KTqCd2r1c - udondan

0
role-base/meta/main.yml 中,您将角色名称定义为 dep。因此,您可以这样调用它:
- hosts: test
  roles:
    - role: dep

我没有将角色“dep”应用于任何主机,它应该作为“base”的依赖项被拉入,就像您在“play.yml”示例中看到的那样。 - Tim Jones

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接