Repository: ansible/ansible

Issue:
-vvvv Ouput for Ansible-Vault
##### ISSUE TYPE

<!--- Pick one below and delete the rest: -->
- Bug Report
##### ANSIBLE VERSION

<!--- Paste verbatim output from “ansible --version” between quotes below -->

```
ansible 2.1.0.0
  config file = /home/aroberts/git/ansible-playbooks/ansible.cfg
  configured module search path = ['/usr/share/ansible']
```
##### CONFIGURATION

<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->

I don't think that this is related to the issue, nor am I the maintainer of our companies ansible config. If necessary I can get what has been changed, but I don't forsee this being an issue.
##### 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.
-->

Ubuntu 14.04
##### SUMMARY

<!--- Explain the problem briefly -->

-vvvv doesn't produce helpful output for decrypting ansible-vault files. 
##### STEPS TO REPRODUCE

Run playbook with different vaulted files, requiring different vault passwords, it will fail. Running with -vvvv isn't helpful at all; it should be.
##### EXPECTED RESULTS

<!--- What did you expect to happen when running the steps above? -->

Useful output for what file failed to decrypt
##### ACTUAL RESULTS

<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->

```
$ ansible-playbook -i inventory/development -e env=development --diff --force-handlers -e "hostlist=host use_samba=False env=development" playbook.yml --ask-vault-pass -vvvv
Using /home/aroberts/git/ansible-playbooks/ansible.cfg as config file
Vault password: 
ERROR! Decryption failed
```



Discussion:

Resolving patch:
diff --git a/lib/ansible/parsing/dataloader.py b/lib/ansible/parsing/dataloader.py
--- a/lib/ansible/parsing/dataloader.py
+++ b/lib/ansible/parsing/dataloader.py
@@ -169,7 +169,7 @@ def _get_file_contents(self, file_name):
             with open(b_file_name, 'rb') as f:
                 data = f.read()
                 if self._vault.is_encrypted(data):
-                    data = self._vault.decrypt(data)
+                    data = self._vault.decrypt(data, filename=b_file_name)
                     show_content = False
 
             data = to_unicode(data, errors='strict')
@@ -339,7 +339,7 @@ def get_real_file(self, file_path):
                     if not self._vault_password:
                         raise AnsibleParserError("A vault password must be specified to decrypt %s" % file_path)
 
-                    data = self._vault.decrypt(data)
+                    data = self._vault.decrypt(data, filename=real_path)
                     # Make a temp file
                     real_path = self._create_content_tempfile(data)
                     self._tempfiles.add(real_path)
diff --git a/lib/ansible/parsing/vault/__init__.py b/lib/ansible/parsing/vault/__init__.py
--- a/lib/ansible/parsing/vault/__init__.py
+++ b/lib/ansible/parsing/vault/__init__.py
@@ -144,7 +144,7 @@ def encrypt(self, data):
         b_tmp_data = self._format_output(b_enc_data)
         return b_tmp_data
 
-    def decrypt(self, data):
+    def decrypt(self, data, filename=None):
         """Decrypt a piece of vault encrypted data.
 
         :arg data: a string to decrypt.  Since vault encrypted data is an
@@ -157,7 +157,10 @@ def decrypt(self, data):
             raise AnsibleError("A vault password must be specified to decrypt data")
 
         if not self.is_encrypted(b_data):
-            raise AnsibleError("input is not encrypted")
+            msg = "input is not encrypted"
+            if filename:
+                msg += "%s is not encrypted" % filename
+            raise AnsibleError(msg)
 
         # clean out header
         b_data = self._split_header(b_data)
@@ -173,7 +176,10 @@ def decrypt(self, data):
         # try to unencrypt data
         b_data = this_cipher.decrypt(b_data, self.b_password)
         if b_data is None:
-            raise AnsibleError("Decryption failed")
+            msg = "Decryption failed"
+            if filename:
+                msg += " on %s" % filename
+            raise AnsibleError(msg)
 
         return b_data
 


Test patch: