Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix][v1.9.0][zos_unarchive]action plugin does not clean up remote temporary files after completion #1073

Original file line number Diff line number Diff line change
@@ -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).
15 changes: 14 additions & 1 deletion plugins/action/zos_unarchive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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()
Expand Down Expand Up @@ -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
ddimatos marked this conversation as resolved.
Show resolved Hide resolved
script."""
self._connection.exec_command("rm -f {0}".format(tempfile_path))