Much requested feature -- allows relative imports of content within roles or relative to any task or handler include (../templates for template ../files for copy)

This commit is contained in:
Michael DeHaan
2013-04-06 12:13:04 -04:00
parent 95f30f0def
commit 892484812e
4 changed files with 102 additions and 9 deletions

View File

@@ -53,10 +53,13 @@ class ActionModule(object):
# look up the files and use the first one we find as src
if 'first_available_file' in inject:
found = False
for fn in self.runner.module_vars.get('first_available_file'):
fnt = utils.template(self.runner.basedir, fn, inject)
fnd = utils.path_dwim(self.runner.basedir, fnt)
if not os.path.exists(fnd) and '_original_file' in inject:
fnd = utils.path_dwim_relative(inject['_original_file'], 'templates', fnd, self.runner.basedir, check=False)
if os.path.exists(fnd):
source = fnt
found = True
@@ -66,6 +69,12 @@ class ActionModule(object):
return ReturnData(conn=conn, comm_ok=False, result=result)
else:
source = utils.template(self.runner.basedir, source, inject)
if '_original_file' in inject:
source = utils.path_dwim_relative(inject['_original_file'], 'templates', source, self.runner.basedir)
else:
source = utils.path_dwim(self.runner.basedir, source)
if dest.endswith("/"):
base = os.path.basename(source)