有条件地调用Ansible角色时,我可以使用自定义变量吗?

时间:2017-06-01 13:08:50

标签: ansible

根据ansible documentation here我使用以下语法在变量“mdb_user”以prod开头时触发角色。

- hosts: category_workstation
  gather_facts: False
  name: common workstation applications
  roles:
    - apps_workstation
    - { role: apps_workstation_production, when: mdb_user.startswith('prod') }

这很好用,但我想知道的是,如果我可以做类似的事情来调整在不同条件下输入角色的变量。例如下面的内容:

- hosts : category_workstation
  name: common workstation applications
  roles:
    - apps_workstation
    - { role: apps_workstation_production, vars={'user':'prod'}, when: mdb_user.startswith('prod')}

目前我不得不使用when和set_fact来在设置角色之前设置正确的变量,而上述方法(如果可能)似乎更简洁。

1 个答案:

答案 0 :(得分:0)

您可以尝试以下内容:


acc|name|group|priority
1  |aa  |g1   |1
2  |ff  |g1   |2
3  |ss  |g1   |2
4  |gg  |g2   |3
5  |uu  |g2   |4
6  |dd  |g2   |4
.  |.   |.    |.
xx |xx  |xx   |x
 
相关问题