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:
parent
9c6ee8d0bb
commit
13a1111dde
1 changed files with 33 additions and 18 deletions
|
@ -94,27 +94,42 @@ class VarsModule(BaseVarsPlugin):
|
|||
|
||||
b_path = to_bytes(os.path.join(path, name))
|
||||
found = []
|
||||
for ext in C.YAML_FILENAME_EXTENSIONS + ['']:
|
||||
|
||||
if '.' in ext:
|
||||
full_path = b_path + to_bytes(ext)
|
||||
elif ext:
|
||||
full_path = b'.'.join([b_path, to_bytes(ext)])
|
||||
# first look for w/o extensions
|
||||
if os.path.exists(b_path):
|
||||
if os.path.isdir(b_path):
|
||||
found.extend(self._get_dir_files(b_path))
|
||||
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):
|
||||
self._display.debug("\tfound %s" % to_text(full_path))
|
||||
if os.path.isdir(full_path):
|
||||
# matched dir name, so use all files included recursively
|
||||
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)
|
||||
if '.' in ext:
|
||||
full_path = b_path + to_bytes(ext)
|
||||
elif ext:
|
||||
full_path = b'.'.join([b_path, to_bytes(ext)])
|
||||
else:
|
||||
full_path = b_path
|
||||
|
||||
if os.path.exists(full_path) and os.path.isfile(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
|
||||
|
|
Loading…
Reference in a new issue