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

19,429 views
Skip to first unread message

Michael DeHaan

unread,
Aug 11, 2012, 9:44:33 AM8/11/12
to ansible...@googlegroups.com
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





martin f krafft

unread,
Jun 19, 2013, 8:26:43 AM6/19/13
to ansible...@googlegroups.com
Dear Michael,

I am replying to an ancient message of yours:

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:

ansible-playbook site.yml --limit '!down'

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

Thoughts?

--
martin | http://madduck.net/ | http://two.sentenc.es/

"durch frauen werden die höhepunkte des lebens bereichert
und die tiefpunkte vermehrt."
- friedrich nietzsche

spamtraps: madduc...@madduck.net
digital_signature_gpg.asc

Michael DeHaan

unread,
Jun 19, 2013, 11:12:31 AM6/19/13
to ansible...@googlegroups.com
I'm fine with patches to support this.

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


--
Michael DeHaan <mic...@ansibleworks.com>
CTO, AnsibleWorks, Inc.
http://www.ansibleworks.com/

Kahlil Hodgson

unread,
Jun 19, 2013, 4:53:37 PM6/19/13
to ansible...@googlegroups.com
I've used

    ansible-playbook site.yml --limit 'all:!down'

in the past.  I assume that still works.

K


Kahlil (Kal) Hodgson                       GPG: C9A02289
Head of Technology                         (m) +61 (0) 4 2573 0382
DealMax Pty Ltd                            (w) +61 (0) 3 9008 5281

Suite 1415
401 Docklands Drive
Docklands VIC 3008 Australia

"All parts should go together without forcing.  You must remember that
the parts you are reassembling were disassembled by you.  Therefore,
if you can't get them together again, there must be a reason.  By all
means, do not use a hammer."  -- IBM maintenance manual, 1925

Michael DeHaan

unread,
Jun 19, 2013, 4:59:02 PM6/19/13
to ansible...@googlegroups.com
Ok, great!


--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

martin f krafft

unread,
Jun 20, 2013, 2:00:28 AM6/20/13
to Kahlil Hodgson, ansible...@googlegroups.com
also sprach Kahlil Hodgson <kahlil....@dealmax.com.au> [2013.06.19.2253 +0200]:
> I've used
>
> 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
"president thieu says he'll quit if he doesn't get more than 50% of
the vote. in a democracy, that's not called quitting."
-- the washington post

spamtraps: madduc...@madduck.net
digital_signature_gpg.asc

Michael DeHaan

unread,
Jun 20, 2013, 12:05:32 PM6/20/13
to ansible...@googlegroups.com, Kahlil Hodgson
Looks good to me.
Reply all
Reply to author
Forward
0 new messages