# How to set vars\_pompt default values

**URL:** <https://forum.ansible.com/t/how-to-set-vars-pompt-default-values/12203>\
**Category:** Ansible Project\
**Created:** [January 15, 2013, 7:25am UTC](https://forum.ansible.com/t/how-to-set-vars-pompt-default-values/12203 "2013-01-15T07:25:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Edu\_el\_Ligre](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@Edu\_el\_Ligre](https://forum.ansible.com/u/Edu_el_Ligre)\
**Post date:** [January 15, 2013, 7:25am UTC](https://forum.ansible.com/t/how-to-set-vars-pompt-default-values/12203/1 "2013-01-15T07:25:10Z")

</div>

Hi there,

I am trying to have some kind of default value when prompting for variables like this:

vars\_prompt:  
branch\_prompt: “Branch to deploy? (master)”

vars:  
branch: “‘$branch\_prompt’ if $branch\_prompt else ‘master’”

also tried some variations with quotes and curly brackets, things like:

branch: “${branch\_default} = ‘${branch\_prompt}’ if $branch else ‘master’”.

I thought you could have python expressions to be evaluated while registering variables, there are examples like this one

is\_color\_blue: “‘$color’ == ‘blue’”

However, I could not even make this work:

vars\_prompt: branch: “Branch to deploy? (master)” vars: branch2: “‘${branch}’ == ‘master’” tasks: - debug: msg=“Branch is ${branch2}” fail=yes

The debug message is just a string: “Branch is ‘’ == ‘master’”

What am I doing wrong? What would be the right way to declare defaults for prompt varialbes?

Thanks

---

<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:** [January 16, 2013, 12:46pm UTC](https://forum.ansible.com/t/how-to-set-vars-pompt-default-values/12203/2 "2013-01-16T12:46:39Z")

</div>

vars\_prompt does not currently provide a way to set a default value.  
I am fine with it having such an option ("default:") if the entry is  
blank if someone wants to add that. I seem to have thought we did  
something like this before, but apparently no.

[https://github.com/ansible/ansible/blob/devel/examples/playbooks/prompts.yml](https://github.com/ansible/ansible/blob/devel/examples/playbooks/prompts.yml)

However it's also true that the expression you printed inthe debug  
statement is just going to print as a string and does not work as you  
expect.

What you want is "when\_string" or the earlier "only\_if" conditional.

---

<div class="post-metadata">

**Author:** ![Eduardo\_Esclapes\_Gim](https://avatars.discourse-cdn.com/v4/letter/e/e274bd/32.png) [@Eduardo\_Esclapes\_Gim](https://forum.ansible.com/u/Eduardo_Esclapes_Gim)\
**Post date:** [January 16, 2013, 2:19pm UTC](https://forum.ansible.com/t/how-to-set-vars-pompt-default-values/12203/3 "2013-01-16T14:19:10Z")

</div>

Thanks Michael,

> However it's also true that the expression you printed inthe debug  
> statement is just going to print as a string and does not work as you  
> expect.

Now I get it. The is\_something variables in the expamples are just  
strings that get evaluated later at the only\_if.

Is there any need for that to be explicit in the docs? May be at he  
"Conditional Execution" epigraph in Advanced Playbooks?

Let me know, I would like to give something back, even if it is only  
one line in the docs.

Thanks again. I just finished my first drupal-deploy playbook and I am  
quitte happy about how easy it was.

---

<div class="post-metadata">

**Author:** ![Rodney\_Quillo](https://avatars.discourse-cdn.com/v4/letter/r/7ba0ec/32.png) [@Rodney\_Quillo](https://forum.ansible.com/u/Rodney_Quillo)\
**Post date:** [January 22, 2013, 2:50am UTC](https://forum.ansible.com/t/how-to-set-vars-pompt-default-values/12203/4 "2013-01-22T02:50:25Z")

</div>

On current devel branch, vars\_prompt now accept default values.

Rodney
