allow empty files in host/group_vars

also remove unused import
fixes #24963
This commit is contained in:
Brian Coca 2017-05-24 09:31:44 -04:00
parent 4b6db5db7c
commit daef6f0911

View file

@ -36,7 +36,6 @@ from ansible import constants as C
from ansible.errors import AnsibleParserError from ansible.errors import AnsibleParserError
from ansible.module_utils._text import to_bytes, to_text from ansible.module_utils._text import to_bytes, to_text
from ansible.plugins.vars import BaseVarsPlugin from ansible.plugins.vars import BaseVarsPlugin
from ansible.utils.path import basedir
from ansible.inventory.host import Host from ansible.inventory.host import Host
from ansible.inventory.group import Group from ansible.inventory.group import Group
from ansible.utils.vars import combine_vars from ansible.utils.vars import combine_vars
@ -71,7 +70,9 @@ class VarsModule(BaseVarsPlugin):
self._display.debug("\tprocessing dir %s" % opath) self._display.debug("\tprocessing dir %s" % opath)
for found in self._find_vars_files(opath, entity.name): for found in self._find_vars_files(opath, entity.name):
self._display.debug("READING %s" % found) self._display.debug("READING %s" % found)
data = combine_vars(data, loader.load_from_file(found, cache=True, unsafe=True)) new_data = loader.load_from_file(found, cache=True, unsafe=True)
if new_data: # ignore empty files
data = combine_vars(data, new_data)
else: else:
self._display.warning("Found %s that is not a directory, skipping: %s" % (subdir, opath)) self._display.warning("Found %s that is not a directory, skipping: %s" % (subdir, opath))