Repository: ansible/ansible

Issue:
vars_prompt does not cast boolean on private
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report


##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
vars_prompt

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
ansible 2.2.1.0
ansible 2.3.0
ansible 2.4.0
```

##### CONFIGURATION
<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->

##### OS / ENVIRONMENT
<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say “N/A” for anything that is not platform-specific.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.
-->

##### SUMMARY
<!--- Explain the problem briefly -->
vars_prompt private does not cast yes/no to boolean. 

##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->

<!--- Paste example playbooks or commands between quotes below -->
```yaml
(ansible2.2) ken@kcelenza-ubuntu:/tmp$ ansible-playbook -i localhost, test.yml
Enter vm name: shows
Enter other name:

PLAY [all] *********************************************************************

TASK [debug] *******************************************************************
ok: [localhost] => {
    "vm_name": "shows"
}

TASK [debug] *******************************************************************
ok: [localhost] => {
    "other_name": "does not"
}

PLAY RECAP *********************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0

(ansible2.2) ken@kcelenza-ubuntu:/tmp$ cat test.yml
- hosts: all
  gather_facts: False
  vars_prompt:
    - name: "vm_name"
      prompt: "Enter vm name"
      private: no
    - name: "other_name"
      prompt: "Enter other name"
      private: "no"
  tasks:
    - debug: var=vm_name
    - debug: var=other_name
(ansible2.2) ken@kcelenza-ubuntu:/tmp$ ansible --version
ansible 2.2.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/etc/ntc/ansible/library', '/etc/ntc/ntc-ansible-plugins/library']
(ansible2.2) ken@kcelenza-ubuntu:/tmp$ workon ansible2.3
(ansible2.3) ken@kcelenza-ubuntu:/tmp$ ansible-playbook -i localhost, test.yml
Enter vm name: shows
Enter other name:

PLAY [all] *********************************************************************************************************************************************************************************************************************************************************************

TASK [debug] *******************************************************************************************************************************************************************************************************************************************************************
ok: [localhost] => {
    "changed": false,
    "vm_name": "shows"
}

TASK [debug] *******************************************************************************************************************************************************************************************************************************************************************
ok: [localhost] => {
    "changed": false,
    "other_name": "does not"
}

PLAY RECAP *********************************************************************************************************************************************************************************************************************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0

(ansible2.3) ken@kcelenza-ubuntu:/tmp$ ansible --version
ansible 2.3.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/etc/ntc/ansible/library', u'/etc/ntc/ntc-ansible-plugins/library']
  python version = 2.7.6 (default, Oct 26 2016, 20:32:47) [GCC 4.8.4]
(ansible2.3) ken@kcelenza-ubuntu:/tmp$ workon ansible2.3
(ansible2.3) ken@kcelenza-ubuntu:/tmp$ workon ansible2.4
(ansible2.4) ken@kcelenza-ubuntu:/tmp$ ansible --version
ansible 2.4.0 (devel 76158db10c) last updated 2017/07/14 11:09:46 (GMT -400)
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/etc/ntc/ansible/library', u'/etc/ntc/ntc-ansible-plugins/library']
  ansible python module location = /home/ken/ansible/lib/ansible
  executable location = /home/ken/.virtualenvs/ansible2.4/bin/ansible
  python version = 2.7.6 (default, Oct 26 2016, 20:32:47) [GCC 4.8.4]
(ansible2.4) ken@kcelenza-ubuntu:/tmp$ ansible-playbook -i localhost, test.yml
Enter vm name: shows
Enter other name:

PLAY [all] *********************************************************************************************************************************************************************************************************************************************************************

TASK [debug] *******************************************************************************************************************************************************************************************************************************************************************
ok: [localhost] => {
    "vm_name": "shows"
}

TASK [debug] *******************************************************************************************************************************************************************************************************************************************************************
ok: [localhost] => {
    "other_name": "does not"
}

PLAY RECAP *********************************************************************************************************************************************************************************************************************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0

(ansible2.4) ken@kcelenza-ubuntu:/tmp$
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->


<!--- Paste verbatim command output between quotes below -->
```
Enter vm name: shows
Enter other name: does not

PLAY [all] *********************************************************************

TASK [debug] *******************************************************************
ok: [localhost] => {
    "vm_name": "shows"
}

TASK [debug] *******************************************************************
ok: [localhost] => {
    "other_name": "does not"
}
```
##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->
 shown above


Discussion:

Resolving patch:
diff --git a/lib/ansible/executor/playbook_executor.py b/lib/ansible/executor/playbook_executor.py
--- a/lib/ansible/executor/playbook_executor.py
+++ b/lib/ansible/executor/playbook_executor.py
@@ -27,6 +27,7 @@
 from ansible.playbook import Playbook
 from ansible.template import Templar
 from ansible.utils.helpers import pct_to_int
+from ansible.module_utils.parsing.convert_bool import boolean
 from ansible.utils.path import makedirs_safe
 from ansible.utils.ssh_functions import check_for_controlpersist
 
@@ -107,8 +108,8 @@ def run(self):
                             vname = var['name']
                             prompt = var.get("prompt", vname)
                             default = var.get("default", None)
-                            private = var.get("private", True)
-                            confirm = var.get("confirm", False)
+                            private = boolean(var.get("private", True))
+                            confirm = boolean(var.get("confirm", False))
                             encrypt = var.get("encrypt", None)
                             salt_size = var.get("salt_size", None)
                             salt = var.get("salt", None)


Test patch: