【问题标题】:Ansible playbook using private git role dependency使用私有 git 角色依赖的 Ansible 剧本
【发布时间】:2016-04-13 05:50:45
【问题描述】:

我在运行具有一组私有角色(即私有 git 存储库中的 Ansible 角色)的 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

有没有办法正确使用私有仓库中的角色依赖项?

【问题讨论】:

    标签: git ansible ansible-playbook


    【解决方案1】:

    看起来这是 1.9 中的错误。我创建了一个 PR (https://github.com/ansible/ansible/pull/13802),但我怀疑它会因为 Ansible 2.0 刚刚发布而被合并。

    【讨论】:

    【解决方案2】:

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

    - hosts: test
      roles:
        - role: dep
    

    【讨论】:

    • 我没有将角色 dep 应用到任何主机,它应该作为 base 的依赖项引入,正如您在 play.yml 示例中看到的那样。
    猜你喜欢
    • 1970-01-01
    • 2015-11-13
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    • 2015-07-31
    • 1970-01-01
    • 1970-01-01
    • 2021-07-25
    相关资源
    最近更新 更多