# subset/limit option in play definition (for applying a play to an intersection of host groups)

**URL:** <https://forum.ansible.com/t/subset-limit-option-in-play-definition-for-applying-a-play-to-an-intersection-of-host-groups/12126>\
**Category:** Ansible Project\
**Tags:** ansible-project\
**Created:** [December 7, 2012, 4:07pm UTC](https://forum.ansible.com/t/subset-limit-option-in-play-definition-for-applying-a-play-to-an-intersection-of-host-groups/12126 "2012-12-07T16:07:29Z")\
**Posts on this page:** 6\
**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:** [December 7, 2012, 4:07pm UTC](https://forum.ansible.com/t/subset-limit-option-in-play-definition-for-applying-a-play-to-an-intersection-of-host-groups/12126/1 "2012-12-07T16:07:29Z")

</div>

> Hi there,
> 
> I'm wondering if it is planned (or already possible) to allow host  
> limits/subsets to be specified in individual plays.
> 
> E.g. if I have a webservers group, a debianservers group and a redhatservers  
> group, it would be useful to have two plays, one to install apache (say)  
> using an apt task and one to install it via yum. In the following example I  
> use the "limit" parameter as that matches the command line switch in  
> ansible-playbook. In the code the keyword "subset" seems to be preferred:

I have no problem with patches to allow limit groups to be set in  
play. I could see this being particularly useful when used  
with the group\_by module.

If the CLI --limit flag is used it should only set the limit for those  
plays that do not have a limit set.

> ---  
> - hosts: webservers  
> - limit: debian  
> - tasks:  
> &nbsp;&nbsp;- apt: ...

FYI -- Putting a dash in front of everything above is incorrect, as a  
dash indicates the start of a new list entry.

> - hosts: webservers  
> - limit: redhat  
> - tasks:  
> &nbsp;&nbsp;- yum: ...
> 
> Please note that this is just an example, and that the real question is how  
> to have a play run on an intersection of host groups. At the moment union  
> (with group1:group2) and difference (with group1:!group2) are possible, and  
> it's only intersection that is lacking.

Agreed

---

<div class="post-metadata">

**Author:** ![Michael\_Liddle](https://avatars.discourse-cdn.com/v4/letter/m/85f322/32.png) [@Michael\_Liddle](https://forum.ansible.com/u/Michael_Liddle)\
**Post date:** [December 7, 2012, 4:33pm UTC](https://forum.ansible.com/t/subset-limit-option-in-play-definition-for-applying-a-play-to-an-intersection-of-host-groups/12126/2 "2012-12-07T16:33:16Z")

</div>

> I have no problem with patches to allow limit groups to be set in  
> play. I could see this being particularly useful when used  
> with the group\_by module.

OK, I’ll look into implementing something. Should I stick with the “limit” keyword?

> If the CLI --limit flag is used it should only set the limit for those  
> plays that do not have a limit set.

Should it not be that the two instances of limit are combined (intersected with each other)?

I.e. if I have both debian and redhat webservers in London and New York, and I run the above plays with CLI --limit london, that shouldn’t be ignored should it? Rather only debian and redhat webservers in london should be touched…

> FYI – Putting a dash in front of everything above is incorrect, as a  
> dash indicates the start of a new list entry.

Ah, typo(s) 🙂

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [December 7, 2012, 4:36pm UTC](https://forum.ansible.com/t/subset-limit-option-in-play-definition-for-applying-a-play-to-an-intersection-of-host-groups/12126/3 "2012-12-07T16:36:31Z")

</div>

That sounds more more logical to me, too.

---

<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:** [December 7, 2012, 4:38pm UTC](https://forum.ansible.com/t/subset-limit-option-in-play-definition-for-applying-a-play-to-an-intersection-of-host-groups/12126/4 "2012-12-07T16:38:33Z")

</div>

Yeah, keeping with the CLI keywords seems best.

> > I have no problem with patches to allow limit groups to be set in  
> > play. I could see this being particularly useful when used  
> > with the group\_by module.
> 
> OK, I'll look into implementing something. Should I stick with the "limit"  
> keyword?
> 
> > If the CLI --limit flag is used it should only set the limit for those  
> > plays that do not have a limit set.
> 
> Should it not be that the two instances of limit are combined (intersected  
> with each other)?

It should work EXACTLY like the command line, in fact, all this would  
be doing would be sourcing the data from the play object rather than  
the CLI value, if one was set.

> I.e. if I have both debian and redhat webservers in London and New York, and  
> I run the above plays with CLI --limit london, that shouldn't be ignored  
> should it? Rather only debian and redhat webservers in london should be  
> touched...

that is pretty much what it does, right? 🙂

---

<div class="post-metadata">

**Author:** ![Michael\_Liddle](https://avatars.discourse-cdn.com/v4/letter/m/85f322/32.png) [@Michael\_Liddle](https://forum.ansible.com/u/Michael_Liddle)\
**Post date:** [December 7, 2012, 4:50pm UTC](https://forum.ansible.com/t/subset-limit-option-in-play-definition-for-applying-a-play-to-an-intersection-of-host-groups/12126/5 "2012-12-07T16:50:17Z")

</div>

But if the CLI --limit was only applied to play objects without their own limit (which is what I thought you meant with “If the CLI --limit flag is used it should only set the limit for those plays that do not have a limit set”), then in my example above the CLI --limit london would be ignored and the play object limits “debian” and “redhat” used instead (and servers in NY would be affected too). No?

---

<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:** [December 7, 2012, 6:03pm UTC](https://forum.ansible.com/t/subset-limit-option-in-play-definition-for-applying-a-play-to-an-intersection-of-host-groups/12126/6 "2012-12-07T18:03:14Z")

</div>

Oh, that.

The limit system is presently only one level of limiting, it must  
appear somewhere in the limit group.

I'd accept patches to make it more additive.
