Ansible:如何包括所有主机,但在特定主机上运行角色?

Ansible:如何包括所有主机,但在特定主机上运行角色?,ansible,roles,hosts,ansible-inventory,ansible-facts,Ansible,Roles,Hosts,Ansible Inventory,Ansible Facts,我试图包括所有主机,因为我想在其他主机配置中使用一个主机事实 但我有 所有人的共同任务 两组的常见任务 单个组的任务 当我尝试以下方法时,所有任务都在所有主机上运行。我如何确保在特定组中应用角色 - hosts: Local:Global:Stream tasks: - include_role: name: global when: host in groups['Global'] - include_role: name: local

我试图包括所有主机,因为我想在其他主机配置中使用一个主机事实

但我有

  • 所有人的共同任务
  • 两组的常见任务
  • 单个组的任务
当我尝试以下方法时,所有任务都在所有主机上运行。我如何确保在特定组中应用角色

- 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']

请尝试
目录\u主机名
。我也更喜欢点语法,不过如果你的名字是对的,那应该没关系

when: inventory_hostname in groups.admin