ansible:在角色中包含角色? [英] ansible: include role in a role?
问题描述
是否可以在角色中重用角色?我的意思不是通过在角色的 meta/main.yml 文件中定义依赖项,而是通过将角色包括直接包含在另一个角色的 tasks/main.yml 中?
Is it possible to reuse a role in a role? I do not mean via defining a dependency in the meta/main.yml file of a role but by including the role in the tasks/main.yml of another role directly?
例如,我在角色手册中定义了几个基本角色,并在角色中定义了一些更高级别的角色.除了某些特定任务之外,我希望高级角色还包括一些基本角色.
For example, I define a couple of basic roles in rolebooks and some more high level roles in roles. I want the high level roles to include some of the basic roles in addition to some specific tasks.
playbooks/
rolebooks/
some_role/
roles/
webtier/
tasks/
main.yml
在 playbooks/roles/webtier/tasks/main.yml 中:
In playbooks/roles/webtier/tasks/main.yml:
- shell: echo 'hello'
- { role: rolebooks/some_role }
- shell: echo 'still busy'
谢谢
推荐答案
老问题但记录:使用 Ansible 2.2+,你很高兴使用 include_role
.正是为了这个目的......请参阅文档此处.
Old question BUT for the record: use Ansible 2.2+ and you're good to go with include_role
. Exactly for this very purpose... see documentation here.
查看 import_role
以及...参见文档 这里
Check out import_role
as well... see documentation here
这篇关于ansible:在角色中包含角色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!