【发布时间】:2020-11-14 17:55:17
【问题描述】:
这是我目前正在使用的 Ansible playbook 示例:
---
- hosts: all
collections:
- mynamespace.my_collection
roles:
- mynamespace.my_role1
- mynamespace.my_role2
- geerlingguy.repo-remi
mynamespace.my_collection 集合是一个自定义集合,其中包含几个角色,即mynamespace.my_role1 和mynamespace.my_role2。
我有一个requirements.yml 文件如下:
---
collections:
- name: git@github.com:mynamespace/my_collection.git
roles:
- name: geerlingguy.repo-remi
version: "2.0.1"
我按如下方式安装集合和角色:
ansible-galaxy collection install -r /home/ansible/requirements.yml --force
ansible-galaxy role install -r /home/ansible/requirements.yml --force
每次我尝试运行 playbook 时都会失败并出现以下错误:
ERROR! the role 'mynamespace.my_role1' was not found in mynamespace.my_collection:ansible.legacy:/home/ansible/roles:/home/ansible_roles:/home/ansible
The error appears to be in '/home/ansible/play.yml': line 42, column 7, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
roles:
- mynamespace.my_role1
^ here
为免生疑问,我尝试了多种方法来定义剧本中的角色,包括mynamespace.my_collection.my_role1(集合中角色的完全限定名称)。
我怀疑我做错了什么或误解了它应该如何工作,但我的理解是一个集合可以包含多个角色,一旦安装了该集合,我应该能够调用集合中的一个或多个角色在我的剧本中使用它,但它似乎对我不起作用。
该错误似乎表明它正在寻找集合中的角色但没有找到它。
该集合安装到路径/home/ansible_collections/mynamespace/my_collection,并且在该目录中是roles/my_role1 和roles/my_role2。
可能是集合内的角色结构有误?
我在 CentOS 8 上使用 Ansible 2.10。
感谢您的建议!
编辑:
我只是想扩展我之前提到的一些内容。我相信文档说应该使用完全限定名称来引用剧本中集合中的角色。
不幸的是,这个错误也:
ERROR! the role 'mynamespace.my_collection.my_role1' was not found in mynamespace.my_collection:ansible.legacy:/home/ansible/roles:/home/ansible_roles:/home/ansible
The error appears to be in '/home/ansible/play.yml': line 42, column 7, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
roles:
- mynamespace.my_collection.my_role1
^ here
【问题讨论】:
-
根据我在文档中收集的信息,您应该完全限定您的角色:
mynamespace.mycollection.role1。这在本文档部分的结尾处注明:docs.ansible.com/ansible/latest/dev_guide/… -
谢谢。我完全同意这就是文档所说的。我已经试过了。我将编辑问题以澄清(我想我已经提到过)。
标签: ansible ansible-role