Sometimes you want to run a playbook on a cross section of your infrastructure.
There are multiple reasons for this.
Assume the following inventory for an example of overlapping groups:
[webservers]
wa
wb
wc
wd
we
[databaseservers]
da
db
dc
dd
de
[site-one]
wa
wb
wc
da
db
dc
[site-two]
wd
we
dd
de
[A]
assume I have a playbook that targets all of my webservers and database servers, however I want to do a rolling deployment.
hosts: webservers
tasks:
- blarg...
hosts: dbservers
tasks:
- blarg...
I can NOW do:
ansible-playbook example.yml --limit site-one
ansible-playbook example.yml --limit site-two
[B]
The same as the above example could be used with --limit stage or --limit production to control inventory. I really don't recommend this though, because leaving off limit
would be pretty dangerous.
[C]
The same could be done to limit a test of an initial production rollout to a small portion of the total hosts, with the intent to run them on the whole group if successful. In this case, just two servers:
ansible-playbook example.yml --limit wa,da
**** NEXT STEPS FOR EXPANDING THIS FEATURE ****
The next steps for this is to make patterns support the concept of range selection.
For instance, the following syntax does NOT work yet, but I want to make it work very soon:
ansible-playbook example.yml --limit all[0%-10%]
The above would run the playbook on the first 10% of all hosts in inventory.
AND
ansible-playbook example.yml --limit webservers[0-99];dbservers[0-5]
The above, hypotethically, would command the first 100 webservers, and the first six database servers.
(This should be pretty easy to do, and will also mean that patterns will be able to support this kind of magic, so you could use the same syntax in /usr/bin/ansible for the first argument.)
Comments and questions welcome!
--Michael