How to set vars_pompt default values

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

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

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.

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.

On current devel branch, vars_prompt now accept default values.

Rodney