I realize now I should have sent this to the devel list.
Will send an issue and proposed patch.
diff --git a/lib/ansible/callbacks.py b/lib/ansible/callbacks.py
index 1abfe68..cbfd315 100644
--- a/lib/ansible/callbacks.py
+++ b/lib/ansible/callbacks.py
@@ -643,7 +643,7 @@ class PlaybookCallbacks(object):
def on_vars_prompt(self, varname, private=True, prompt=None,
encrypt=None, confirm=False, salt_size=None, salt=None, default=None):
- if prompt and default:
+ if prompt and default is not None:
msg = "%s [%s]: " % (prompt, default)
elif prompt:
msg = "%s: " % prompt
On Friday, April 18, 2014 11:41:24 AM UTC-7, Jim Kleckner wrote:
>
> See the input and output below for some oddity with vars_prompt.
>
> First, note that yes is being coerced to True but no results in a missing
> default.
> Quoting it works around this at the expense of no longer being boolean.
>
> Second, would it make sense to have a boolean option to have vars_prompt
> do the smart coercion of yes/no/true/false to boolean?
> I find that the result being a string requires pushing | bool down
> through the code.
>
> Thanks, Jim
>
>
> ---
> - name: Default values of prompts
> hosts: localhost
> gather_facts: no
> vars_prompt:
> - name: yes_val_from_prompt
> prompt: Test for boolean value - enter yes or no
> default: yes
> private: no
> # Bug? Why does the default value not get printed?
> - name: no_val_from_prompt
> prompt: Test for boolean value - enter yes or no
> default: no
> private: no
> - name: yes_string_val_from_prompt
> prompt: Test for boolean value - enter yes or no
> default: "yes"
> private: no
> # Bug? Why does the default value not get printed?
> - name: no_string_val_from_prompt
> prompt: Test for boolean value - enter yes or no
> default: "no"
> private: no
> tasks:
> - debug: var=yes_val_from_prompt
> - debug: var=no_val_from_prompt
> - debug: var=yes_string_val_from_prompt
> - debug: var=no_string_val_from_prompt
>
>
> Results in:
>
>
> ansible-playbook -i inv test_prompt_no_default.yml
>
> Test for boolean value - enter yes or no [True]:
> Test for boolean value - enter yes or no: <======= Missing default
> Test for boolean value - enter yes or no [yes]:
> Test for boolean value - enter yes or no [no]:
>
> PLAY [Default values of prompts]
> **********************************************
>
> TASK: [debug var=yes_val_from_prompt]
> *****************************************
> ok: [127.0.0.1] => {
> "yes_val_from_prompt": "True" <========== coerced to True
> }
>
> TASK: [debug var=no_val_from_prompt]
> ******************************************
> ok: [127.0.0.1] => {
> "no_val_from_prompt": "" <======== Missing default
> }
>
> TASK: [debug var=yes_string_val_from_prompt]
> **********************************
> ok: [127.0.0.1] => {
> "yes_string_val_from_prompt": "yes" <======= Not coerced to True
> (asexpected
> )
> }
>
> TASK: [debug var=no_string_val_from_prompt]
> ***********************************
> ok: [127.0.0.1] => {
> "no_string_val_from_prompt": "no"
> }
>
> PLAY RECAP
> ********************************************************************
>
> 127.0.0.1 : ok=4 changed=0 unreachable=0 failed=
> 0
>
>
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/462b1836-ed1c-4173-8bae-800106ab8f7f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.