# What is prompt variable working scope?

**URL:** <https://forum.ansible.com/t/what-is-prompt-variable-working-scope/12671>\
**Category:** Ansible Project\
**Created:** [April 12, 2013, 1:43am UTC](https://forum.ansible.com/t/what-is-prompt-variable-working-scope/12671 "2013-04-12T01:43:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rella.guo](https://avatars.discourse-cdn.com/v4/letter/r/d2c977/32.png) [@rella.guo](https://forum.ansible.com/u/rella.guo)\
**Post date:** [April 12, 2013, 1:43am UTC](https://forum.ansible.com/t/what-is-prompt-variable-working-scope/12671/1 "2013-04-12T01:43:45Z")

</div>

Prompt variable working scope is inventory host scope or playbook scope?  
Basically, variable is inventory host scope. But prompt vars seem not.

main.yml includes 1.yml and 2.yml.1.yml creates prompt variable var1 and its target hosts are host1 and host2.  
2.yml wants to use the var1 and its target host is host1.

I suppose 2.yml can get var1, but indeed not. Who can confirm it?

**main.yml**

---

<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:** [April 12, 2013, 1:49pm UTC](https://forum.ansible.com/t/what-is-prompt-variable-working-scope/12671/2 "2013-04-12T13:49:37Z")

</div>

vars\_prompt variables are set on the play.

In nearly all cases, --extra-vars on the ansible-playbook command line is a better way to go.

---

<div class="post-metadata">

**Author:** ![Garrett\_Plasky](https://avatars.discourse-cdn.com/v4/letter/g/5f9b8f/32.png) [@Garrett\_Plasky](https://forum.ansible.com/u/Garrett_Plasky)\
**Post date:** [March 25, 2014, 10:54pm UTC](https://forum.ansible.com/t/what-is-prompt-variable-working-scope/12671/3 "2014-03-25T22:54:03Z")

</div>

Can you explain why you think this is a “better way to go” in nearly all cases? I recently found out the hard way (after a bit of head-banging) that vars\_prompt only applies to the current play and also doesn’t apply to included playbooks. Since you also cannot pass parameterized options to included playbooks as you can with roles, there’s effectively no way to pass a variable gathered via vars\_prompt to a child playbook without using -e. I’ve resorted to using -e for now, but I find it rather odd that I now have to wrap Ansible in “something else” (Shell script, Python, etc.) in order to programmatically input a simple variable to the playbook and have it accessible in places one could reasonably expect it to be.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [March 26, 2014, 11:41pm UTC](https://forum.ansible.com/t/what-is-prompt-variable-working-scope/12671/4 "2014-03-26T23:41:45Z")

</div>

> Can you explain why you think this is a "better way to go" in nearly all  
> cases?

For one, because it can be used non-interactively. For two, for the  
question you raise below...

> I recently found out the hard way (after a bit of head-banging) that  
> vars\_prompt only applies to the current play and also doesn't apply to  
> included playbooks.

This is implied by the fact that vars\_prompt is an attribute of the play.  
It's just the same as if doing "vars" or "vars\_files" in that play.

> Since you also cannot pass parameterized options to included playbooks as  
> you can with roles, there's effectively no way to pass a variable gathered  
> via vars\_prompt to a child playbook without using -e. I've resorted to  
> using -e for now, but I find it rather odd that I now have to wrap  
> Ansible in "something else" (Shell script, Python, etc.) in order to  
> programmatically input a simple variable to the playbook and have it  
> accessible in places one could reasonably expect it to be.

Sorry!

There's no construct for asking questions at "overall playbook" level since  
playbooks are just a list data structure of plays, there is no where to  
attach this.

We could add a 'vars\_prompt\_global' kind of thing that left them in global  
scope, but I'd be worried a bit more about language sprawl, so you may be  
stuck.
