问题
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