---
- 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_promptansible-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 (as expected)
}
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 diff --git a/lib/ansible/callbacks.py b/lib/ansible/callbacks.pyindex 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
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/462b1836-ed1c-4173-8bae-800106ab8f7f%40googlegroups.com.--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/65983255-c93f-413e-902c-65ef2654d82a%40googlegroups.com.