Repository: ansible/ansible

Issue:
include_vars will only include *.yml, *.yaml, and *.json files but isn't documented as a breaking change
##### ISSUE TYPE
- Bug Report

##### COMPONENT NAME

Action plugins, specifically include_vars action plugin
##### ANSIBLE VERSION

I'm using 2.2 RC3

```
$ ansible --version
ansible 2.2.0.0
  config file = 
  configured module search path = Default w/o overrides
```
##### CONFIGURATION

N/A
##### OS / ENVIRONMENT

N/A
##### SUMMARY

#17207 introduced a requirement that include_vars will only include files with .yaml, .yml, and .json extensions. This breaks some of our existing playbooks that have YAML-formatted vars files without a .yml or .yaml extension.

Further, this isn't documented as a breaking change.
##### STEPS TO REPRODUCE

Should be trivial to reproduce
##### EXPECTED RESULTS

Load vars files without the specific set of extensions
##### ACTUAL RESULTS

```
TASK [include_vars] ************************************************************
task path: foo.yml:8
fatal: [localhost]: FAILED! => {
    "ansible_facts": {}, 
    "changed": false, 
    "failed": true, 
    "invocation": {
        "module_args": {
            "_raw_params": "my_vars_files_without_extension"
        }, 
        "module_name": "include_vars"
    }, 
    "message": "my_vars_files_without_extension does not have a valid extension: yaml, yml, json"
}
```



Discussion:
Same issue with RC3-RC4

I don't think that 13261b7 copmpletely fixes the issue. At the very least, it should be mentioned as a breaking change in the CHANGELOG. But, why is this requirement even necessary in the first place?

This is a bug, the restriction should only apply to the new feature that allows including directories.

docs were missing for new features, merged now and backported to 2.2 https://github.com/ansible/ansible-modules-core/pull/4609, testing bugfix to revert restriction when specifying a file.


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
@@ -226,7 +226,7 @@ def _is_valid_file_ext(self, source_file):
                 return success
         return success
 
-    def _load_files(self, filename):
+    def _load_files(self, filename, validate_extensions=False):
         """ Loads a file and converts the output into a valid Python dict.
         Args:
             filename (str): The source file.
@@ -237,7 +237,7 @@ def _load_files(self, filename):
         results = dict()
         failed = False
         err_msg = ''
-        if not self._is_valid_file_ext(filename):
+        if validate_extensions and not self._is_valid_file_ext(filename):
             failed = True
             err_msg = (
                 '{0} does not have a valid extension: {1}'
@@ -287,7 +287,7 @@ def _load_files_in_dir(self, root_dir, var_files):
 
             if not stop_iter and not failed:
                 if path.exists(filepath) and not self._ignore_file(filename):
-                    failed, err_msg, loaded_data = self._load_files(filepath)
+                    failed, err_msg, loaded_data = self._load_files(filepath, validate_extensions=True)
                     if not failed:
                         results.update(loaded_data)
 


Test patch: