Add ignore_unknown_extensions to include_vars for dir (#35809)

processing to ignore non-valid file extensions

Fixes #35745

Signed-off-by: Adam Miller <admiller@redhat.com>
pull/40977/head
Adam Miller 7 years ago committed by ansibot
parent 61c6f4fda1
commit 39f7e055a4

@ -56,6 +56,12 @@ options:
description: description:
- List of file extensions to read when using C(dir). - List of file extensions to read when using C(dir).
default: [yaml, yml, json] default: [yaml, yml, json]
ignore_unkown_extensions:
version_added: "2.7"
description:
- Ignore unkown file extensions within the directory. This allows users to specify a directory containing vars files
that are intermingled with non vars files extension types (For example, a directory with a README in it and vars files)
default: False
free-form: free-form:
description: description:
- This module allows you to specify the 'file' option directly without any other options. - This module allows you to specify the 'file' option directly without any other options.

@ -32,7 +32,7 @@ class ActionModule(ActionBase):
TRANSFERS_FILES = False TRANSFERS_FILES = False
VALID_FILE_EXTENSIONS = ['yaml', 'yml', 'json'] VALID_FILE_EXTENSIONS = ['yaml', 'yml', 'json']
VALID_DIR_ARGUMENTS = ['dir', 'depth', 'files_matching', 'ignore_files', 'extensions'] VALID_DIR_ARGUMENTS = ['dir', 'depth', 'files_matching', 'ignore_files', 'extensions', 'ignore_unknown_extensions']
VALID_FILE_ARGUMENTS = ['file', '_raw_params'] VALID_FILE_ARGUMENTS = ['file', '_raw_params']
VALID_ALL = ['name'] VALID_ALL = ['name']
@ -68,6 +68,7 @@ class ActionModule(ActionBase):
self.depth = self._task.args.get('depth', None) self.depth = self._task.args.get('depth', None)
self.files_matching = self._task.args.get('files_matching', None) self.files_matching = self._task.args.get('files_matching', None)
self.ignore_unknown_extensions = self._task.args.get('ignore_unknown_extensions', False)
self.ignore_files = self._task.args.get('ignore_files', None) self.ignore_files = self._task.args.get('ignore_files', None)
self.valid_extensions = self._task.args.get('extensions', self.VALID_FILE_EXTENSIONS) self.valid_extensions = self._task.args.get('extensions', self.VALID_FILE_EXTENSIONS)
@ -274,6 +275,12 @@ class ActionModule(ActionBase):
stop_iter = True stop_iter = True
if not stop_iter and not failed: if not stop_iter and not failed:
if self.ignore_unknown_extensions:
if path.exists(filepath) and not self._ignore_file(filename) and self._is_valid_file_ext(filename):
failed, err_msg, loaded_data = self._load_files(filepath, validate_extensions=True)
if not failed:
results.update(loaded_data)
else:
if path.exists(filepath) and not self._ignore_file(filename): if path.exists(filepath) and not self._ignore_file(filename):
failed, err_msg, loaded_data = self._load_files(filepath, validate_extensions=True) failed, err_msg, loaded_data = self._load_files(filepath, validate_extensions=True)
if not failed: if not failed:

Loading…
Cancel
Save