# Some praise, and a question about how to best reuse playbooks

**URL:** <https://forum.ansible.com/t/some-praise-and-a-question-about-how-to-best-reuse-playbooks/11799>\
**Category:** Ansible Project\
**Tags:** ansible-project\
**Created:** [August 15, 2012, 11:54am UTC](https://forum.ansible.com/t/some-praise-and-a-question-about-how-to-best-reuse-playbooks/11799 "2012-08-15T11:54:43Z")\
**Posts on this page:** 1\
**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 15, 2012, 11:54am UTC](https://forum.ansible.com/t/some-praise-and-a-question-about-how-to-best-reuse-playbooks/11799/1 "2012-08-15T11:54:43Z")

</div>

Ok, so there are quite a few things you can use now to limit the hosts  
you run to.

A)

hosts: $hosts

and ansible-playbook foo.yml --extra-vars="hosts=patternGoesHere"

This allows you to use a playbook and not code the name of the hosts in it.

B)

ansible-playbook.yml --limit somePatternMatchingASubSetOfHosts

Allows you to specify a group in the playbook with the "hosts:" line  
and then run on only a subset of those groups/hosts.

C)

ansible-playbook.yml foo.yml -i "host1.example.com,host2.example.com2"  
# note if you have only one host and want to do this, they must end in a comma  
# note the inventory file variables and groups is ignored if you do this

I want a nicer syntax for this hack, and we'll have one, but this  
works for now. I just want something that makes it clear it's not  
selecting those hosts out of your inventory file.  
(If you want that, use --limit)

D)

depending on complexity, you could write your own tool using the  
Playbook API, looking at /usr/bin/ansible-playbook as a reference.  
The API is generally stable.

Hope that helps!

--Michael
