Repository: ansible/ansible

Issue:
ask_sudo_pass in ansible.cfg has no effect
Ansible 1.9.1 Mac OSX 10.10

I set in ansible.cfg:

```
ask_sudo_pass = True
```

But when running the playbook it does not ask for a password. At cli **--ask-sudo-pass** works fine.
Also **ask_pass** in the ansible.cfg works as expected.

My ansible.cfg:

```
###########################
# Config file for ansible #
###########################

# NOTES:
# o If [ssh_connection] Pipelining = True then when using “sudo:” operations
#   you must first disable ‘requiretty’ in /etc/sudoers on all managed hosts.

[defaults]
hostfile            = hosts/hosts.ini
remote_user         = root
nocows              = 0
ask_sudo_pass       = True
vault_password_file = ~/.ansible/vault/password.txt

[ssh_connection]
pipelining  = True
```



Discussion:
I see the same issue on Ubuntu 14.04.2, ansible 1.9.1. I was using Ansible 1.5.4 and my tasks ran fine, I upgraded to 1.9.1 and it stopped prompting for my password (for sudo). If I add a "-K" flag to the ansible-playbook command it prompts as it should.

confirmed, this was probably introduced in 1.9 with the become update.


Resolving patch:
diff --git a/lib/ansible/utils/__init__.py b/lib/ansible/utils/__init__.py
--- a/lib/ansible/utils/__init__.py
+++ b/lib/ansible/utils/__init__.py
@@ -1024,9 +1024,9 @@ def base_parser(constants=C, usage="", output_opts=False, runas_opts=False,
 
     if runas_opts:
         # priv user defaults to root later on to enable detecting when this option was given here
-        parser.add_option('-K', '--ask-sudo-pass', default=False, dest='ask_sudo_pass', action='store_true',
+        parser.add_option('-K', '--ask-sudo-pass', default=constants.DEFAULT_ASK_SUDO_PASS, dest='ask_sudo_pass', action='store_true',
             help='ask for sudo password (deprecated, use become)')
-        parser.add_option('--ask-su-pass', default=False, dest='ask_su_pass', action='store_true',
+        parser.add_option('--ask-su-pass', default=constants.DEFAULT_ASK_SU_PASS, dest='ask_su_pass', action='store_true',
             help='ask for su password (deprecated, use become)')
         parser.add_option("-s", "--sudo", default=constants.DEFAULT_SUDO, action="store_true", dest='sudo',
             help="run operations with sudo (nopasswd) (deprecated, use become)")
diff --git a/v2/ansible/cli/__init__.py b/v2/ansible/cli/__init__.py
--- a/v2/ansible/cli/__init__.py
+++ b/v2/ansible/cli/__init__.py
@@ -245,9 +245,9 @@ def base_parser(usage="", output_opts=False, runas_opts=False, meta_opts=False,
 
         if runas_opts:
             # priv user defaults to root later on to enable detecting when this option was given here
-            parser.add_option('-K', '--ask-sudo-pass', default=False, dest='ask_sudo_pass', action='store_true',
+            parser.add_option('-K', '--ask-sudo-pass', default=C.DEFAULT_ASK_SUDO_PASS, dest='ask_sudo_pass', action='store_true',
                 help='ask for sudo password (deprecated, use become)')
-            parser.add_option('--ask-su-pass', default=False, dest='ask_su_pass', action='store_true',
+            parser.add_option('--ask-su-pass', default=C.DEFAULT_ASK_SU_PASS, dest='ask_su_pass', action='store_true',
                 help='ask for su password (deprecated, use become)')
             parser.add_option("-s", "--sudo", default=C.DEFAULT_SUDO, action="store_true", dest='sudo',
                 help="run operations with sudo (nopasswd) (deprecated, use become)")


Test patch: