mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 21:00:22 -07:00
Adding "follow" param for file/copy options
Also modifies the template action plugin to use this new param when executing the file/copy modules for templating so that links are preserved correctly. Fixes #8998
This commit is contained in:
parent
79a2e586fe
commit
b376e208c7
7 changed files with 96 additions and 13 deletions
|
@ -33,9 +33,6 @@ class ActionModule(object):
|
|||
def run(self, conn, tmp, module_name, module_args, inject, complex_args=None, **kwargs):
|
||||
''' handler for template operations '''
|
||||
|
||||
# note: since this module just calls the copy module, the --check mode support
|
||||
# can be implemented entirely over there
|
||||
|
||||
if not self.runner.is_playbook:
|
||||
raise errors.AnsibleError("in current versions of ansible, templates are only usable in playbooks")
|
||||
|
||||
|
@ -121,6 +118,7 @@ class ActionModule(object):
|
|||
src=xfered,
|
||||
dest=dest,
|
||||
original_basename=os.path.basename(source),
|
||||
follow=True,
|
||||
)
|
||||
module_args_tmp = utils.merge_module_args(module_args, new_module_args)
|
||||
|
||||
|
@ -132,12 +130,18 @@ class ActionModule(object):
|
|||
res.diff = dict(before=dest_contents, after=resultant)
|
||||
return res
|
||||
else:
|
||||
# if we're running in check mode, we still want the file module
|
||||
# to execute, since we can't know if anything would be changed here,
|
||||
# so we inject the check mode param into the module args and rely on
|
||||
# the file module to report its changed status
|
||||
# when running the file module based on the template data, we do
|
||||
# not want the source filename (the name of the template) to be used,
|
||||
# since this would mess up links, so we clear the src param and tell
|
||||
# the module to follow links
|
||||
new_module_args = dict(
|
||||
src=None,
|
||||
follow=True,
|
||||
)
|
||||
# be sure to inject the check mode param into the module args and
|
||||
# rely on the file module to report its changed status
|
||||
if self.runner.noop_on_check(inject):
|
||||
new_module_args = dict(CHECKMODE=True)
|
||||
module_args = utils.merge_module_args(module_args, new_module_args)
|
||||
new_module_args['CHECKMODE'] = True
|
||||
module_args = utils.merge_module_args(module_args, new_module_args)
|
||||
return self.runner._execute_module(conn, tmp, 'file', module_args, inject=inject, complex_args=complex_args)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue