# Help understanding how the limit flag works with the ansible-playbook command

**URL:** <https://forum.ansible.com/t/help-understanding-how-the-limit-flag-works-with-the-ansible-playbook-command/17451>\
**Category:** Ansible Project\
**Created:** [February 5, 2015, 12:17am UTC](https://forum.ansible.com/t/help-understanding-how-the-limit-flag-works-with-the-ansible-playbook-command/17451 "2015-02-05T00:17:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Richardson](https://avatars.discourse-cdn.com/v4/letter/d/a4c791/32.png) [@Daniel\_Richardson](https://forum.ansible.com/u/Daniel_Richardson)\
**Post date:** [February 5, 2015, 12:17am UTC](https://forum.ansible.com/t/help-understanding-how-the-limit-flag-works-with-the-ansible-playbook-command/17451/1 "2015-02-05T00:17:06Z")

</div>

I ran into what seemed to me like a strange problem today, but I might just lack the understanding to know what was happening.  
Let’s say you have a YAML file called ec2.yml to run against that looks like this:

`

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [February 5, 2015, 11:11am UTC](https://forum.ansible.com/t/help-understanding-how-the-limit-flag-works-with-the-ansible-playbook-command/17451/2 "2015-02-05T11:11:02Z")

</div>

limit filters the available host list, since both hosts have the host2  
tag, it does not modify the list of hosts in the play.

it reads like this once resolved

- hosts: "tag\_ansible\_hosts1:&tag\_ansible\_host2"  
...

- hosts: "tag\_ansible\_hosts2:&tag\_ansible\_hosts2"

It does not limit to an existing play declaration, but imposes  
additional limits to those. What you seem to want is play tags.

- hosts: tag\_ansible\_host1  
&nbsp;&nbsp;tags:  
&nbsp;&nbsp;&nbsp;&nbsp;- host1  
&nbsp;&nbsp;roles:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- role1  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- role2

- hosts: tag\_ansible\_host2  
&nbsp;&nbsp;tags:  
&nbsp;&nbsp;&nbsp;&nbsp;- host2  
&nbsp;&nbsp;roles:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- role2

and then run ansible with -t 'host2'

---

<div class="post-metadata">

**Author:** ![Daniel\_Richardson](https://avatars.discourse-cdn.com/v4/letter/d/a4c791/32.png) [@Daniel\_Richardson](https://forum.ansible.com/u/Daniel_Richardson)\
**Post date:** [February 6, 2015, 4:48pm UTC](https://forum.ansible.com/t/help-understanding-how-the-limit-flag-works-with-the-ansible-playbook-command/17451/3 "2015-02-06T16:48:21Z")

</div>

Thanks so much Brian. That makes a lot of sense now.
