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/3c3766ca-b46f-410f-a0e0-7d4b4117ca53%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.