Repository: ansible/ansible

Issue:
Invalid yml causes include_vars to hang or freeze without output
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and devel branch are affected too.
Always add information AFTER of these html comments.
-->

I made some attempt to sift through the 3,511 issues. Apology for adding yet another to this hopelessly large list. I did *not* set-up for development and try to reproduce.

##### ISSUE TYPE
<!--- Pick one below and delete the rest -->
 - Bug Report
 
##### COMPONENT NAME
<!---
Insert below this comment the name of the module, plugin, task or feature.
Do not include extra details here, e.g. "vyos_command" not "the network module vyos_command" or the full path
-->
include_vars

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes below -->
```
ansible 2.4.3.0
  config file = /Users/dclo/Documents/ansible/ansible.cfg
  configured module search path = ['/Users/dclo/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.6/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.6.4 (default, Mar 22 2018, 13:54:22) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)]
```

##### CONFIGURATION
<!---
If using Ansible 2.4 or above, paste the results of "ansible-config dump --only-changed"
Otherwise, mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->
```
DEFAULT_HOST_LIST(/Users/dclo/Documents/ansible/ansible.cfg) = ['/Users/dclo/Documents/ansible/staging']
DEFAULT_VAULT_PASSWORD_FILE(/Users/dclo/Documents/ansible/ansible.cfg) = /Users/dclo/Documents/ansible/.vault_pass
```

##### 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.
-->
macOS High Sierra 10.13.3

##### SUMMARY
<!--- Explain the problem briefly -->
`ansible-playbook test.yml -vvv` outputs the beginning of the `include_vars` task and then hangs.

##### 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.
-->
- Create a vars file with ansible-vault (create/edit) that has malformed yaml.
- Include it in the playbook.

<!--- Paste example playbooks or commands between quotes below -->
```yaml
---
- hosts: all
   gather_facts: no
   tasks:
   - include_vars: "vars/vault.yml"
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
Ansible outputs syntax error on the yaml file.

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->
Ansible hangs

<!--- Paste verbatim command output between quotes below -->
```
TASK [include_vars] ********************************************************************************
task path: /Users/dclo/Documents/ansible/test.yml:5
^CProcess WorkerProcess-2:
 [ERROR]: User interrupted execution
```



Discussion:
Files identified in the description:
* [lib/ansible/modules/utilities/logic/include_vars.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/utilities/logic/include_vars.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
cc @linuxdynasty
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->
I've submitted a fix for this issue at #38194 

Resolving patch:
diff --git a/lib/ansible/plugins/action/include_vars.py b/lib/ansible/plugins/action/include_vars.py
--- a/lib/ansible/plugins/action/include_vars.py
+++ b/lib/ansible/plugins/action/include_vars.py
@@ -236,7 +236,7 @@ def _load_files(self, filename, validate_extensions=False):
             data = to_text(b_data, errors='surrogate_or_strict')
 
             self.show_content = show_content
-            data = self._loader.load(data, show_content)
+            data = self._loader.load(data, file_name=filename, show_content=show_content)
             if not data:
                 data = dict()
             if not isinstance(data, dict):


Test patch: