# New feature "--limit" on ansible-playbook, confining patterns to part of your inventory

**URL:** <https://forum.ansible.com/t/new-feature-limit-on-ansible-playbook-confining-patterns-to-part-of-your-inventory/11790>\
**Category:** Ansible Project\
**Created:** [August 11, 2012, 1:44pm UTC](https://forum.ansible.com/t/new-feature-limit-on-ansible-playbook-confining-patterns-to-part-of-your-inventory/11790 "2012-08-11T13:44:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [August 11, 2012, 1:44pm UTC](https://forum.ansible.com/t/new-feature-limit-on-ansible-playbook-confining-patterns-to-part-of-your-inventory/11790/1 "2012-08-11T13:44:33Z")

</div>

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:  
&nbsp;&nbsp;&nbsp;- blarg...

hosts: dbservers  
tasks:  
&nbsp;&nbsp;&nbsp;&nbsp;- 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

---

<div class="post-metadata">

**Author:** ![martin\_f\_krafft](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@martin\_f\_krafft](https://forum.ansible.com/u/martin_f_krafft)\
**Post date:** [June 19, 2013, 12:26pm UTC](https://forum.ansible.com/t/new-feature-limit-on-ansible-playbook-confining-patterns-to-part-of-your-inventory/11790/2 "2013-06-19T12:26:43Z")

</div>

Dear Michael,

I am replying to an ancient message of yours:

&nbsp;&nbsp;[https://groups.google.com/d/msg/ansible-project/qfoeqytbRE4/SI58rlzeEwMJ](https://groups.google.com/d/msg/ansible-project/qfoeqytbRE4/SI58rlzeEwMJ)

Do you think it would be useful to be able to use logical NOT in  
--limit calls? I have a group 'down' into which I put hosts that are  
currently unreachable, and it would be good to be able to say:

&nbsp;&nbsp;ansible-playbook site.yml --limit '!down'

Rather than having to append ':!down' to the hosts: line of every  
playbook.

Thoughts?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [June 19, 2013, 3:12pm UTC](https://forum.ansible.com/t/new-feature-limit-on-ansible-playbook-confining-patterns-to-part-of-your-inventory/11790/3 "2013-06-19T15:12:31Z")

</div>

I’m fine with patches to support this.

I believe in the past previous attempts were incomplete and couldn’t be merged in.

---

<div class="post-metadata">

**Author:** ![kahlil.hodgson](https://avatars.discourse-cdn.com/v4/letter/k/b9bd4f/32.png) [@kahlil.hodgson](https://forum.ansible.com/u/kahlil.hodgson)\
**Post date:** [June 19, 2013, 8:53pm UTC](https://forum.ansible.com/t/new-feature-limit-on-ansible-playbook-confining-patterns-to-part-of-your-inventory/11790/4 "2013-06-19T20:53:37Z")

</div>

I’ve used

ansible-playbook site.yml --limit ‘all:!down’

in the past. I assume that still works.

K

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [June 19, 2013, 8:59pm UTC](https://forum.ansible.com/t/new-feature-limit-on-ansible-playbook-confining-patterns-to-part-of-your-inventory/11790/5 "2013-06-19T20:59:02Z")

</div>

Ok, great!

---

<div class="post-metadata">

**Author:** ![martin\_f\_krafft](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@martin\_f\_krafft](https://forum.ansible.com/u/martin_f_krafft)\
**Post date:** [June 20, 2013, 6:00am UTC](https://forum.ansible.com/t/new-feature-limit-on-ansible-playbook-confining-patterns-to-part-of-your-inventory/11790/6 "2013-06-20T06:00:28Z")

</div>

also sprach Kahlil Hodgson \<kahlil.hodgson@dealmax.com.au\> [2013.06.19.2253 +0200]:

> I've used
> 
> &nbsp;&nbsp;&nbsp;&nbsp;ansible-playbook site.yml --limit 'all:!down'
> 
> in the past. I assume that still works.

Thanks for the hint!  
[https://github.com/ansible/ansible/pull/3275](https://github.com/ansible/ansible/pull/3275)

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [June 20, 2013, 4:05pm UTC](https://forum.ansible.com/t/new-feature-limit-on-ansible-playbook-confining-patterns-to-part-of-your-inventory/11790/7 "2013-06-20T16:05:32Z")

</div>

Looks good to me.
