2

我正在尝试使用以下命令运行 ansible,

ansible-playbook provision.yml -l webserver

我的主机文件包含以下主机组,

[webclient]
172.29.4.75
[webserver]
172.29.4.76

我的 provision.yml 还包含 2 个主机,如下所示,

- hosts: webclient
  user: centos
  roles: 
   - nginx
   - nvm
- hosts: webserver
  user: centos
  roles: 
   - tomcat

我的问题甚至认为我使用为 webclient 指定的“-l webserver”角色也运行在 webclient 主机中。如何控制它只运行特定的主机组?

4

1 回答 1

2

我的问题甚至认为我使用为 webclient 指定的“-l webserver”角色也运行在 webclient 主机中。如何控制它只运行特定的主机组?

这通常意味着您在webserverwebclient组下具有相同的主机。

传递-l webserver告诉 Ansible 使用清单中的所有主机,这些主机属于webserver组。
当 Ansible 开始播放- hosts: webclient时,它会在清单中搜索匹配项,然后从limit 参数中减少与主机的匹配项。因此,如果您有一些同时位于 和 下的主机webserverwebclientAnsible 将为它们执行webclientplay 任务。

于 2017-01-06T08:35:10.190 回答