# Is it possible to include playbook and pass a host to it ?

**URL:** <https://forum.ansible.com/t/is-it-possible-to-include-playbook-and-pass-a-host-to-it/13153>\
**Category:** Ansible Project\
**Created:** [July 18, 2013, 1:54pm UTC](https://forum.ansible.com/t/is-it-possible-to-include-playbook-and-pass-a-host-to-it/13153 "2013-07-18T13:54:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lars\_svenson](https://avatars.discourse-cdn.com/v4/letter/l/b782af/32.png) [@lars\_svenson](https://forum.ansible.com/u/lars_svenson)\
**Post date:** [July 18, 2013, 1:54pm UTC](https://forum.ansible.com/t/is-it-possible-to-include-playbook-and-pass-a-host-to-it/13153/1 "2013-07-18T13:54:27Z")

</div>

Hello community,

I’m a outer playbook like this

> - hosts: $SERVER  
> user: root  
> connection: ssh
> 
> vars\_prompt:
> 
> - name: “SERVER”  
> prompt: “\nEnter servername\n”  
> private: no
> 
> tasks:
> 
> - name: do stuff

my inner playbook should be included at **the end** of the first playbook and should work on the same server. How could I do it at the end?

> * * *
> 
> - hosts: $SERVER  
> user: ansible  
> connection: ssh  
> sudo: yes

By now I couldn’t figure a way out to pass this the Server var to the second playbook?

Any suggestions? or is the hosts var not meant to be passed through playbooks.

Thanks a lot

---

<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:** [July 18, 2013, 2:02pm UTC](https://forum.ansible.com/t/is-it-possible-to-include-playbook-and-pass-a-host-to-it/13153/2 "2013-07-18T14:02:30Z")

</div>

first, they are plays, playbook is a list of plays, plays cannot include other plays (they must be at same level) but they can include tasks and roles.

you can use the $SERVER variable if you pass it as an extravar -e “SERVER=myhost” this will work for all playbooks included in the same commandline.

you might also want to leave it as a group and use --limit to include/exclude which servers you run against. Also, --list-hosts is good to test what will be targeted.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [July 18, 2013, 8:57pm UTC](https://forum.ansible.com/t/is-it-possible-to-include-playbook-and-pass-a-host-to-it/13153/3 "2013-07-18T20:57:55Z")

</div>

First off – please do not use $foo.

The new way to do variables, standardized in Ansible is “{{ foo }}”.

This allows much easier access to complex variable data.

If everyone stops saying $foo I will also be able to repeat myself less 🙂

yes, you can pass in things via --extra-args like Brian said, but --limit is definitely the preferred way to do this if you are comfortable with the idea that if you leave off --limit it would run on everything. You might not be, in which case, consider the “-e” technique.
