ansible:在角色中包含角色? [英] ansible: include role in a role?

查看:98
本文介绍了ansible:在角色中包含角色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在角色中重用角色?我的意思不是通过在角色的meta/main.yml文件中定义依赖关系,而是直接在其他角色的task/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

在剧本/角色/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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆