From 5ae85488a2b25546aed039dc684baee92e5b6f67 Mon Sep 17 00:00:00 2001 From: Eero Aaltonen Date: Sun, 1 Mar 2026 23:19:57 +0200 Subject: [PATCH] fixup use named temporary file --- plugins/action/pgp_keyring.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/plugins/action/pgp_keyring.py b/plugins/action/pgp_keyring.py index 48901117fc..28891e8b3f 100644 --- a/plugins/action/pgp_keyring.py +++ b/plugins/action/pgp_keyring.py @@ -73,31 +73,28 @@ class ActionModule(ActionBase): raise AnsibleActionFail("%s: %s" % (type(e).__name__, to_text(e))) new_task = self._task.copy() - local_tempdir = tempfile.mkdtemp(dir=C.DEFAULT_LOCAL_TMP) - try: - result_file = os.path.join(local_tempdir, os.path.basename(source)) - with open(to_bytes(result_file, errors='surrogate_or_strict'), 'wb') as f: - f.write(bytes(key)) + with tempfile.NamedTemporaryFile('wb', delete=True, delete_on_close=False) as f: + f.write(bytes(key)) + f.flush() + f.close() new_task.args.update( dict( - src=result_file, + src=f.file.name, dest=dest, follow=follow, ), ) # call with ansible.legacy prefix to eliminate collisions with collections while still allowing local override copy_action = self._shared_loader_obj.action_loader.get('ansible.legacy.copy', - task=new_task, - connection=self._connection, - play_context=self._play_context, - loader=self._loader, - templar=self._templar, - shared_loader_obj=self._shared_loader_obj) + task=new_task, + connection=self._connection, + play_context=self._play_context, + loader=self._loader, + templar=self._templar, + shared_loader_obj=self._shared_loader_obj) return copy_action.run(task_vars=task_vars) - finally: - shutil.rmtree(to_bytes(local_tempdir, errors='surrogate_or_strict')) finally: self._remove_tmp_path(self._connection._shell.tmpdir)