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?
This usually means that you have same host under
webserver
andwebclient
groups.Passing
-l webserver
tells Ansible to use all host from inventory, that are underwebserver
group.When Ansible starts this play
- hosts: webclient
, it searches for matches in inventory and then reduce the match with hosts fromlimit
argument. So if you have some host that is both underwebserver
andwebclient
, Ansible will execute tasks fromwebclient
play for them.