mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 06:12:51 +00:00
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:
@@ -56,6 +56,8 @@ class ActionModule(object):
|
||||
for fn in inject.get('first_available_file'):
|
||||
fn = utils.template(self.runner.basedir, fn, inject)
|
||||
fn = utils.path_dwim(self.runner.basedir, fn)
|
||||
if not os.path.exists(fn) and '_original_file' in inject:
|
||||
fn = utils.path_dwim_relative(inject['_original_file'], 'files', fn, self.runner.basedir, check=False)
|
||||
if os.path.exists(fn):
|
||||
source = fn
|
||||
found = True
|
||||
@@ -76,7 +78,11 @@ class ActionModule(object):
|
||||
source = tmp_content
|
||||
else:
|
||||
source = utils.template(self.runner.basedir, source, inject)
|
||||
source = utils.path_dwim(self.runner.basedir, source)
|
||||
if '_original_file' in inject:
|
||||
source = utils.path_dwim_relative(inject['_original_file'], 'files', source, self.runner.basedir)
|
||||
else:
|
||||
source = utils.path_dwim(self.runner.basedir, source)
|
||||
|
||||
|
||||
local_md5 = utils.md5(source)
|
||||
if local_md5 is None:
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user