Commit b9050ecf by Brian Coca

fixed file lookup pathing in dwim functinos, now does specific paths and…

fixed file lookup pathing in dwim functinos, now does specific paths and priorities and is commented
fixes #11672 as cwd is now not part of thos paths:
if full path is supplied, used that
parent d412bc72
...@@ -194,32 +194,47 @@ class DataLoader(): ...@@ -194,32 +194,47 @@ class DataLoader():
else: else:
return os.path.abspath(os.path.join(self._basedir, given)) return os.path.abspath(os.path.join(self._basedir, given))
def path_dwim_relative(self, role_path, dirname, source): def path_dwim_relative(self, path, dirname, source):
''' find one file in a directory one level up in a dir named dirname relative to current ''' ''' find one file in a role/playbook dirs with/without dirname subdir '''
basedir = os.path.dirname(role_path) search = []
if os.path.islink(basedir): isrole = False
basedir = unfrackpath(basedir)
template2 = os.path.join(basedir, dirname, source) # I have full path, nothing else needs to be looked at
if source.startswith('~') or source.startswith('/'):
search.append(self.path_dwim(source))
else: else:
template2 = os.path.join(basedir, '..', dirname, source) # base role/play path + templates/files/vars + relative filename
search.append(os.path.join(path, dirname, source))
basedir = unfrackpath(path)
# is it a role and if so make sure you get correct base path
if path.endswith('tasks') and os.path.exists(os.path.join(path,'main.yml')) \
or os.path.exists(os.path.join(path,'tasks/main.yml')):
isrole = True
if path.endswith('tasks'):
basedir = unfrackpath(os.path.dirname(path))
cur_basedir = self._basedir
self.set_basedir(basedir)
# resolved base role/play path + templates/files/vars + relative filename
search.append(self.path_dwim(os.path.join(basedir, dirname, source)))
self.set_basedir(cur_basedir)
source1 = os.path.join(role_path, dirname, source) if isrole and not source.endswith(dirname):
if os.path.exists(source1): # look in role's tasks dir w/o dirname
return source1 search.append(self.path_dwim(os.path.join(basedir, 'tasks', source)))
cur_basedir = self._basedir # try to create absolute path for loader basedir + templates/files/vars + filename
self.set_basedir(basedir) search.append(self.path_dwim(os.path.join(dirname,source)))
source2 = self.path_dwim(template2)
if os.path.exists(source2): # try to create absolute path for loader basedir + filename
self.set_basedir(cur_basedir) search.append(self.path_dwim(source))
return source2
self.set_basedir(cur_basedir)
obvious_local_path = self.path_dwim(source) for candidate in search:
if os.path.exists(obvious_local_path): if os.path.exists(candidate):
#self.set_basedir(cur_basedir) break
return obvious_local_path
return source2 return candidate
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment