diff --git a/changelogs/fragments/1073-action_plugin_does_not_clean_up_remote_temporary_files_after_completion.yml b/changelogs/fragments/1073-action_plugin_does_not_clean_up_remote_temporary_files_after_completion.yml new file mode 100644 index 000000000..6532e60ae --- /dev/null +++ b/changelogs/fragments/1073-action_plugin_does_not_clean_up_remote_temporary_files_after_completion.yml @@ -0,0 +1,4 @@ +bugfixes: + - zos_unarchive - When unarchiving USS files, the module left temporary files on the remote. + Change now removes temporary files. + (https://github.com/ansible-collections/ibm_zos_core/pull/1073). \ No newline at end of file diff --git a/plugins/action/zos_unarchive.py b/plugins/action/zos_unarchive.py index d808647ef..6e679d62d 100644 --- a/plugins/action/zos_unarchive.py +++ b/plugins/action/zos_unarchive.py @@ -46,6 +46,9 @@ def run(self, tmp=None, task_vars=None): module_args = self._task.args.copy() + tmp_files = "" + uss_format = None + if module_args.get("remote_src", False): result.update( self._execute_module( @@ -67,9 +70,10 @@ def run(self, tmp=None, task_vars=None): source = os.path.realpath(source) if format_name in USS_SUPPORTED_FORMATS: - dest = self._execute_module( + tmp_files = dest = self._execute_module( module_name="tempfile", module_args={}, task_vars=task_vars, ).get("path") + uss_format = format_name elif format_name in MVS_SUPPORTED_FORMATS: if dest_data_set is None: dest_data_set = dict() @@ -120,4 +124,13 @@ def run(self, tmp=None, task_vars=None): ) else: result.update(dict(failed=True)) + + if not module_args.get("remote_src", False) and uss_format: + self._remote_cleanup(tmp_files) + return result + + def _remote_cleanup(self, tempfile_path): + """Removes the temporary file in a managed node created for a local + script.""" + self._connection.exec_command("rm -f {0}".format(tempfile_path))