问题描述
我正在尝试使用以下命令运行ansible,
I am trying to run ansible with the following command,
ansible-playbook provision.yml -l webserver
我的主机文件包含以下主机组,
And my hosts file contains the following host groups,
[webclient]
172.29.4.75
[webserver]
172.29.4.76
我的Provision.yml还包含以下2个主机,
My provision.yml also contains 2 hosts as below,
- hosts: webclient
user: centos
roles:
- nginx
- nvm
- hosts: webserver
user: centos
roles:
- tomcat
我的问题甚至被认为我使用为Webclient指定的"-l Webserver"角色也可以在webclient主机中运行.如何控制它仅运行特定的主机组?
My issue here is even thought I use "-l webserver" roles specified for webclient also runs in webclient hosts. How can I control it to run only specific host groups?
推荐答案
这通常意味着您在webserver
和webclient
组下具有相同的主机.
This usually means that you have same host under webserver
and webclient
groups.
传递-l webserver
告诉Ansible使用清单中webserver
组下的所有主机.
当Ansible开始此播放- hosts: webclient
时,它将在清单中搜索匹配项,然后从limit
参数减少与主机的匹配项.因此,如果您的主机同时位于webserver
和webclient
下,Ansible将执行webclient
中的任务为它们播放.
Passing -l webserver
tells Ansible to use all host from inventory, that are under webserver
group.
When Ansible starts this play - hosts: webclient
, it searches for matches in inventory and then reduce the match with hosts from limit
argument. So if you have some host that is both under webserver
and webclient
, Ansible will execute tasks from webclient
play for them.
这篇关于在特定主机组上运行ansible的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!