mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 14:22:46 +00:00
tighter host/group_var discovery
now only loads nonext or valid yaml extensions only first file gets loaded directories must match name (initially) so no name.yml is loaded anymore
This commit is contained in:
@@ -94,27 +94,42 @@ class VarsModule(BaseVarsPlugin):
|
|||||||
|
|
||||||
b_path = to_bytes(os.path.join(path, name))
|
b_path = to_bytes(os.path.join(path, name))
|
||||||
found = []
|
found = []
|
||||||
for ext in C.YAML_FILENAME_EXTENSIONS + ['']:
|
|
||||||
|
|
||||||
if '.' in ext:
|
# first look for w/o extensions
|
||||||
full_path = b_path + to_bytes(ext)
|
if os.path.exists(b_path):
|
||||||
elif ext:
|
if os.path.isdir(b_path):
|
||||||
full_path = b'.'.join([b_path, to_bytes(ext)])
|
found.extend(self._get_dir_files(b_path))
|
||||||
else:
|
else:
|
||||||
full_path = b_path
|
found.append(b_path)
|
||||||
|
else:
|
||||||
|
# add valid extensions to name
|
||||||
|
for ext in C.YAML_FILENAME_EXTENSIONS:
|
||||||
|
|
||||||
if os.path.exists(full_path):
|
if '.' in ext:
|
||||||
self._display.debug("\tfound %s" % to_text(full_path))
|
full_path = b_path + to_bytes(ext)
|
||||||
if os.path.isdir(full_path):
|
elif ext:
|
||||||
# matched dir name, so use all files included recursively
|
full_path = b'.'.join([b_path, to_bytes(ext)])
|
||||||
for spath in os.listdir(full_path):
|
|
||||||
if spath.startswith('.'):
|
|
||||||
continue
|
|
||||||
full_spath = os.path.join(full_path, spath)
|
|
||||||
if os.path.isdir(full_spath):
|
|
||||||
found.extend(self._find_vars_files(full_spath, ''))
|
|
||||||
else:
|
|
||||||
found.append(full_spath)
|
|
||||||
else:
|
else:
|
||||||
|
full_path = b_path
|
||||||
|
|
||||||
|
if os.path.exists(full_path) and os.path.isfile(full_path):
|
||||||
found.append(full_path)
|
found.append(full_path)
|
||||||
|
break
|
||||||
|
return found
|
||||||
|
|
||||||
|
def _get_dir_files(self, path):
|
||||||
|
|
||||||
|
found = []
|
||||||
|
for spath in os.listdir(path):
|
||||||
|
if not spath.startswith('.'): # skip hidden
|
||||||
|
|
||||||
|
ext = os.path.splitext()[-1]
|
||||||
|
full_spath = os.path.join(path, spath)
|
||||||
|
|
||||||
|
if os.path.isdir(full_spath) and not ext: # recursive search if dir
|
||||||
|
found.extend(self._get_dir_files(full_spath))
|
||||||
|
elif os.path.isfile(full_spath) and (not ext or ext in C.YAML_FILENAME_EXTENSIONS):
|
||||||
|
# only consider files with valid extensions or no extension
|
||||||
|
found.append(full_spath)
|
||||||
|
|
||||||
return found
|
return found
|
||||||
|
|||||||
Reference in New Issue
Block a user