我有一个问题是运行带有一组私有角色的Ansible playbook(即私有git存储库中的Ansible角色) .
例如,我有一个使用角色 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 回答
看起来这是1.9中的一个错误 . 我创建了一个PR(https://github.com/ansible/ansible/pull/13802),但我怀疑它会被合并,因为Ansible 2.0刚刚发布 .
在
role-base/meta/main.yml
中,您将角色名称定义为dep
. 因此你调用它像: