Pass context to copy module
With previous way of calling copy module we were not passing context, which might be very important. Simple example is check_mode that previously was not respected when passing task to copy. Change-Id: I89a2dddab4338fbe27877d03b8b48a37f24912c4
This commit is contained in:
parent
5070371edd
commit
a04d034c00
@ -941,14 +941,14 @@ class ActionModule(ActionBase):
|
||||
resultant = self._check_templar(data=resultant)
|
||||
|
||||
# run the copy module
|
||||
new_module_args = self._task.args.copy()
|
||||
new_module = self._task.copy()
|
||||
# Access to protected method is unavoidable in Ansible
|
||||
transferred_data = self._transfer_data(
|
||||
self._connection._shell.join_path(tmp, 'source'),
|
||||
self._connection._shell.join_path(tmp, os.path.basename(source)),
|
||||
resultant
|
||||
)
|
||||
if LooseVersion(__ansible_version__) < LooseVersion("2.6"):
|
||||
new_module_args.update(
|
||||
new_module.args.update(
|
||||
dict(
|
||||
src=transferred_data,
|
||||
dest=_vars['dest'],
|
||||
@ -957,7 +957,7 @@ class ActionModule(ActionBase):
|
||||
),
|
||||
)
|
||||
else:
|
||||
new_module_args.update(
|
||||
new_module.args.update(
|
||||
dict(
|
||||
src=transferred_data,
|
||||
dest=_vars['dest'],
|
||||
@ -967,28 +967,20 @@ class ActionModule(ActionBase):
|
||||
)
|
||||
|
||||
# Remove data types that are not available to the copy module
|
||||
new_module_args.pop('config_overrides', None)
|
||||
new_module_args.pop('config_type', None)
|
||||
new_module_args.pop('list_extend', None)
|
||||
new_module_args.pop('ignore_none_type', None)
|
||||
new_module_args.pop('default_section', None)
|
||||
new_module_args.pop('yml_multilines', None)
|
||||
|
||||
# While this is in the copy module we dont want to use it.
|
||||
new_module_args.pop('remote_src', None)
|
||||
|
||||
# Content from config_template is converted to src
|
||||
new_module_args.pop('content', None)
|
||||
|
||||
# remove render enablement option
|
||||
new_module_args.pop('render_template', None)
|
||||
for arg in ['config_overrides', 'config_type', 'list_extend'
|
||||
'ignore_none_type', 'default_section', 'yml_multilines',
|
||||
'remote_src', 'content', 'render_template']:
|
||||
new_module.args.pop(arg, None)
|
||||
|
||||
# Run the copy module
|
||||
rc = self._execute_module(
|
||||
module_name='copy',
|
||||
module_args=new_module_args,
|
||||
task_vars=task_vars
|
||||
)
|
||||
copy_action = self._shared_loader_obj.action_loader.get('ansible.legacy.copy',
|
||||
task=new_module,
|
||||
connection=self._connection,
|
||||
play_context=self._play_context,
|
||||
loader=self._loader,
|
||||
templar=self._templar,
|
||||
shared_loader_obj=self._shared_loader_obj)
|
||||
rc = copy_action.run(task_vars=task_vars)
|
||||
copy_changed = rc.get('changed')
|
||||
if not copy_changed:
|
||||
rc['changed'] = changed
|
||||
|
Loading…
Reference in New Issue
Block a user