在特定主机组上运行 ansible [英] Run ansible on specific hosts group

查看:31
本文介绍了在特定主机组上运行 ansible的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下命令运行 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?

推荐答案

我的问题是我什至认为我使用为 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?

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

This usually means that you have same host under webserver and webclient groups.

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

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆