diff --git a/changelogs/fragments/85816-wsl-cache-files.yml b/changelogs/fragments/85816-wsl-cache-files.yml new file mode 100644 index 00000000000..0ecf10abc6f --- /dev/null +++ b/changelogs/fragments/85816-wsl-cache-files.yml @@ -0,0 +1,2 @@ +bugfixes: + - cache plugins - close temp cache file before moving it to fix error on WSL. (https://github.com/ansible/ansible/pull/85816) diff --git a/lib/ansible/plugins/cache/__init__.py b/lib/ansible/plugins/cache/__init__.py index 4ec276bca67..ec94fb1e12e 100644 --- a/lib/ansible/plugins/cache/__init__.py +++ b/lib/ansible/plugins/cache/__init__.py @@ -162,6 +162,7 @@ class BaseFileCacheModule(BaseCacheModule): except OSError as ex: display.error_as_warning(f"Error in {self.plugin_name!r} cache plugin while trying to write to {tmpfile_path!r}.", exception=ex) try: + os.close(tmpfile_handle) # os.rename fails if handle is still open in WSL os.rename(tmpfile_path, cachefile) os.chmod(cachefile, mode=S_IRWU_RG_RO) except OSError as ex: