# Why are hosts embedded in a play?

**URL:** <https://forum.ansible.com/t/why-are-hosts-embedded-in-a-play/15185>\
**Category:** Ansible Project\
**Created:** [May 7, 2014, 2:11pm UTC](https://forum.ansible.com/t/why-are-hosts-embedded-in-a-play/15185 "2014-05-07T14:11:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sampsont](https://avatars.discourse-cdn.com/v4/letter/s/fbc32d/32.png) [@sampsont](https://forum.ansible.com/u/sampsont)\
**Post date:** [May 7, 2014, 2:11pm UTC](https://forum.ansible.com/t/why-are-hosts-embedded-in-a-play/15185/1 "2014-05-07T14:11:33Z")

</div>

I’m a newcomer but there’s one thing that bothers me. It seems that plays always have the hosts to be acted on embedded in the play itself. What if you wanted to run a play against different hosts? For example, you might want to run the play against your test setup. If all goes well, you might want to run it against your East servers and then to West and then…

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [May 7, 2014, 2:23pm UTC](https://forum.ansible.com/t/why-are-hosts-embedded-in-a-play/15185/2 "2014-05-07T14:23:44Z")

</div>

We don’t put out dev/test/staging/prod servers all in one inventory file. We have separate inventories for each individual “environment”.

Additionally, we would target something like:

hosts: web

And then if we wanted to only target our web servers in “east”, we would use --limit, such as:

ansible-playbook -i production --limit east some-playbook.yml

or even:

ansible-playbook -i production --limit web:&east some-playbook.yml

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [May 7, 2014, 3:29pm UTC](https://forum.ansible.com/t/why-are-hosts-embedded-in-a-play/15185/3 "2014-05-07T15:29:25Z")

</div>

there are many ways around this, Matt demonstrated one (I happen to use the  
same). You can also have a unified inventory file and used --limit against  
that (--limit 'production').

Another popular method is by making the hosts entry parameterized:

hosts: "web:{{target}}"

now you can pass -e 'target=&production' in the command line or any other  
combination that is allowed by host patterns
