Repository: ansible/ansible

Issue:
Unhandled unexpected exception when passing empty vault password to ansible-console
<!---
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
console

##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
% ansible --version
ansible 2.2.1.0
  config file = 
  configured module search path = Default w/o overrides
```

##### CONFIGURATION
<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->
N/A

##### 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.
-->
N/A

##### SUMMARY
<!--- Explain the problem briefly -->
Ansible console throws unexpected exception stacktrace on empty vault password.

##### 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 -->
```
$ ansible-console localhost --ask-vault-pass
<press enter>
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
Continue on without vault password. And either run the tasks or error out on not being able to decrypt encountered vault.

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->
```
% ansible-console localhost --ask-vault-pass -vvv
No config file found; using defaults
Vault password: 
ERROR! Unexpected Exception: string index out of range
the full traceback was:

Traceback (most recent call last):
  File "/usr/local/bin/ansible-console", line 103, in <module>
    exit_code = cli.run()
  File "/usr/local/lib/python2.7/dist-packages/ansible/cli/console.py", line 427, in run
    vault_pass = self.ask_vault_passwords()[0]
IndexError: string index out of range
```



Discussion:
Looking at all uses of the `ask_vault_passwords()` method, only console.py does a hard array index reference in the form of `self.ask_vault_passwords()[0]`. The others all simply do `self.ask_vault_passwords()` prior to handing it over to `loader.set_vault_password()`.

Resolving patch:
diff --git a/lib/ansible/cli/console.py b/lib/ansible/cli/console.py
--- a/lib/ansible/cli/console.py
+++ b/lib/ansible/cli/console.py
@@ -423,7 +423,7 @@ def run(self):
             vault_pass = CLI.read_vault_password_file(self.options.vault_password_file, loader=self.loader)
             self.loader.set_vault_password(vault_pass)
         elif self.options.ask_vault_pass:
-            vault_pass = self.ask_vault_passwords()[0]
+            vault_pass = self.ask_vault_passwords()
             self.loader.set_vault_password(vault_pass)
 
         self.variable_manager = VariableManager()


Test patch: