使用 ansible "win_file" 模块删除文件夹会出错,提示路径太长

using ansible "win_file" module to remove a folder gives error saying path too long

我正在使用 win_file ansible 模块删除目录。但是,当它 运行 是剧本时,我看到以下错误:

"msg": "Failed to delete C:\product\eclipse-cpp-2019-06-R-win32-x86_64\eclipse\plugins\com.amazonaws.eclipse.elasticbeanstalk_1.0.0.v201807201743\com\amazonaws\eclipse\elasticbeanstalk\server\ui\configEditor: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters."

Ansible 剧本 (uninstall.yml) 正在通过 UCD (UrbanCode Deploy) 运行。这是我的ansible代码:

- name: Remove install_home folder
win_file:
   path: "{{install_home}}"
   state: absent

任何人都想知道上述错误是否是由 OS、Ansible、UCD 或限制引起的。我将不胜感激 thoughts/guidance 如何克服上述问题。

非常感谢

这是来自 OS 的限制,根据 this:

In editions of Windows before Windows 10 version 1607, the maximum length for a path is MAX_PATH, which is defined as 260 characters. In later versions of Windows, changing a registry key or using the Group Policy tool is required to remove the limit. See Maximum Path Length Limitation for full details.

要防止此问题:

要指定加长路径,请使用 "\?\" 前缀。例如"\?\D:\very long path"。最大路径32,767个字符是近似值,因为“\?” prefix 可能会在 运行 时被系统扩展为更长的字符串,并且此扩展适用于总长度。

例如:

"\?\C:\product\eclipse-cpp-2019-06-R-win32-x86_64\eclipse\plugins\com.amazonaws.eclipse.elasticbeanstalk_1.0.0.v201807201743\com\amazonaws\eclipse\elasticbeanstalk\server\ui\configEditor"