【问题标题】:Ansible: How to Include all hosts but run roles on particular hosts? [duplicate]Ansible:如何包括所有主机但在特定主机上运行角色? [复制]
【发布时间】:2018-11-23 08:57:33
【问题描述】:

我正在尝试包含所有主机,因为我想在其他主机配置中使用一个主机事实。

但我有

  • 所有人的共同任务
  • 两组共同的任务
  • 单个小组的任务。

当我尝试以下方式时,所有任务都在所有主机上运行。如何确保在特定组中应用角色?

- hosts: Local:Global:Stream

  tasks:
  - include_role:
      name: global
    when: host in groups['Global']

  - include_role:
      name: local
    when: host in groups['Local']

  - include_role:
      name: stream
    when: host in groups['Stream']

【问题讨论】:

    标签: ansible roles hosts ansible-inventory ansible-facts


    【解决方案1】:

    试试inventory_hostname。我也更喜欢点语法,不过如果你的名字是对的,那应该没关系。

    when: inventory_hostname in groups.admin
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-06
      • 1970-01-01
      • 1970-01-01
      • 2022-11-04
      • 2017-03-22
      • 1970-01-01
      相关资源
      最近更新 更多