mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
got first_available working with copy
This commit is contained in:
parent
11f1d99a5b
commit
a6ca133da8
1 changed files with 21 additions and 27 deletions
|
@ -43,14 +43,12 @@ class ActionModule(ActionBase):
|
||||||
dest = self._task.args.get('dest', None)
|
dest = self._task.args.get('dest', None)
|
||||||
raw = boolean(self._task.args.get('raw', 'no'))
|
raw = boolean(self._task.args.get('raw', 'no'))
|
||||||
force = boolean(self._task.args.get('force', 'yes'))
|
force = boolean(self._task.args.get('force', 'yes'))
|
||||||
|
faf = task_vars.get('first_available_file', None)
|
||||||
|
|
||||||
# FIXME: first available file needs to be reworked somehow...
|
if (source is None and content is None and faf is None) or dest is None:
|
||||||
#if (source is None and content is None and not 'first_available_file' in inject) or dest is None:
|
return dict(failed=True, msg="src (or content) and dest are required")
|
||||||
# result=dict(failed=True, msg="src (or content) and dest are required")
|
elif (source is not None or faf is not None) and content is not None:
|
||||||
# return ReturnData(conn=conn, result=result)
|
return dict(failed=True, msg="src and content are mutually exclusive")
|
||||||
#elif (source is not None or 'first_available_file' in inject) and content is not None:
|
|
||||||
# result=dict(failed=True, msg="src and content are mutually exclusive")
|
|
||||||
# return ReturnData(conn=conn, result=result)
|
|
||||||
|
|
||||||
# Check if the source ends with a "/"
|
# Check if the source ends with a "/"
|
||||||
source_trailing_slash = False
|
source_trailing_slash = False
|
||||||
|
@ -65,7 +63,7 @@ class ActionModule(ActionBase):
|
||||||
try:
|
try:
|
||||||
# If content comes to us as a dict it should be decoded json.
|
# If content comes to us as a dict it should be decoded json.
|
||||||
# We need to encode it back into a string to write it out.
|
# We need to encode it back into a string to write it out.
|
||||||
if isinstance(content, dict):
|
if isinstance(content, dict) or isinstance(content, list):
|
||||||
content_tempfile = self._create_content_tempfile(json.dumps(content))
|
content_tempfile = self._create_content_tempfile(json.dumps(content))
|
||||||
else:
|
else:
|
||||||
content_tempfile = self._create_content_tempfile(content)
|
content_tempfile = self._create_content_tempfile(content)
|
||||||
|
@ -73,27 +71,23 @@ class ActionModule(ActionBase):
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
return dict(failed=True, msg="could not write content temp file: %s" % err)
|
return dict(failed=True, msg="could not write content temp file: %s" % err)
|
||||||
|
|
||||||
###############################################################################################
|
|
||||||
# FIXME: first_available_file needs to be reworked?
|
|
||||||
###############################################################################################
|
|
||||||
# if we have first_available_file in our vars
|
# if we have first_available_file in our vars
|
||||||
# look up the files and use the first one we find as src
|
# look up the files and use the first one we find as src
|
||||||
#elif 'first_available_file' in inject:
|
elif faf:
|
||||||
# found = False
|
found = False
|
||||||
# for fn in inject.get('first_available_file'):
|
for fn in faf:
|
||||||
# fn_orig = fn
|
fn_orig = fn
|
||||||
# fnt = template.template(self.runner.basedir, fn, inject)
|
fnt = self._templar.template(fn)
|
||||||
# fnd = utils.path_dwim(self.runner.basedir, fnt)
|
fnd = self._loader.path_dwim_relative(self._task._role._role_path, 'files', fnt)
|
||||||
# if not os.path.exists(fnd) and '_original_file' in inject:
|
of = task_vars.get('_original_file', None)
|
||||||
# fnd = utils.path_dwim_relative(inject['_original_file'], 'files', fnt, self.runner.basedir, check=False)
|
if not os.path.exists(fnd) and of is not None:
|
||||||
# if os.path.exists(fnd):
|
fnd = self._loader.path_dwim_relative(of, 'files', fnt)
|
||||||
# source = fnd
|
if os.path.exists(fnd):
|
||||||
# found = True
|
source = fnd
|
||||||
# break
|
found = True
|
||||||
# if not found:
|
break
|
||||||
# results = dict(failed=True, msg="could not find src in first_available_file list")
|
if not found:
|
||||||
# return ReturnData(conn=conn, result=results)
|
return dict(failed=True, msg="could not find src in first_available_file list")
|
||||||
###############################################################################################
|
|
||||||
else:
|
else:
|
||||||
if self._task._role is not None:
|
if self._task._role is not None:
|
||||||
source = self._loader.path_dwim_relative(self._task._role._role_path, 'files', source)
|
source = self._loader.path_dwim_relative(self._task._role._role_path, 'files', source)
|
||||||
|
|
Loading…
Reference in a new issue