已归录

方法一:通过 roles section 区域调用

---
- hosts: remote.example.com
  roles:
    - role1
    - role2
---
- hosts: remote.example.com
  roles:
    - role: role1
    - role: role2
      var1: val1
      var2: val2

这儿给 role2 传递了两个变量,其等价写法为:

---
- hosts: remote.example.com
  roles:
    - role: role1
    - { role: role2, var1: val1, var2: val2 }

方法二:通过 task 来调用

- name: execute a role as a task
  hosts: remote.example.com
  tasks:
    - name: a normal task
      debug:
        msg: 'first task'
    - name: a task to include role1
      include_role: role1      

include_role: dynamically include a role
import_role: statically import a role

-- By 许望(RHCA、OCM、VCP)
最后修改:2020 年 06 月 02 日 05 : 01 PM
如果觉得我的文章对你有用,请随意赞赏