Run ansible on specific hosts group

你说的曾经没有我的故事 提交于 2019-12-25 07:49:46

问题


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

My provision.yml also contains 2 hosts as below,

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

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?


回答1:


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?

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

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.



来源:https://stackoverflow.com/questions/41500463/run-ansible-on-specific-hosts-group

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!