community.windows.win_unzip 模块 – 在 Windows 节点上解压缩文件和归档
注意
此模块是 community.windows 集合(版本 2.3.0)的一部分。
如果您正在使用 ansible
包,您可能已经安装了此集合。它不包含在 ansible-core
中。要检查是否已安装,请运行 ansible-galaxy collection list
。
要安装它,请使用:ansible-galaxy collection install community.windows
。您需要满足更多要求才能使用此模块,有关详细信息,请参阅要求。
要在 playbook 中使用它,请指定:community.windows.win_unzip
。
概要
解压缩压缩文件和归档。
原生支持 .zip 文件。
支持 Powershell Community Extensions (PSCX) 模块支持的其他格式(基本上 7zip 支持的所有格式)。
对于非 Windows 目标,请改用 ansible.builtin.unarchive 模块。
要求
执行此模块的主机需要满足以下要求。
PSCX
参数
参数 |
注释 |
---|---|
如果此文件或目录存在,则不会提取指定的 src。 |
|
解压缩后删除 zip 文件。 选项
|
|
zip 文件的目标位置(提供目录的绝对路径)。如果它不存在,将创建该目录。 |
|
如果 zip 文件使用密码加密。 向密码参数传递值需要安装 PSCX 模块。 |
|
递归展开 src 文件中的压缩文件。 设置为 选项
|
|
要解压缩的文件(提供绝对路径)。 |
备注
注意
此模块实际上不是幂等的,它每次都会提取归档,并报告更改。
对于提取 .zip 以外的任何压缩类型,需要 PowerShellCommunityExtensions (PSCX) 模块。此模块(与 PSCX 结合使用)能够递归解压缩提供的 src zip 文件中的文件,并且还具有多种其他压缩类型的功能。如果目标目录不存在,则会在解压缩文件之前创建该目录。指定 rm 参数将在提取后强制删除 src 文件。
另请参阅
另请参阅
- ansible.builtin.unarchive
(可选)从本地机器复制归档文件后解压缩它。
示例
# This unzips a library that was downloaded with win_get_url, and removes the file after extraction
# $ ansible -i hosts -m win_unzip -a "src=C:\LibraryToUnzip.zip dest=C:\Lib remove=yes" all
- name: Unzip a bz2 (BZip) file
community.windows.win_unzip:
src: C:\Users\Phil\Logs.bz2
dest: C:\Users\Phil\OldLogs
creates: C:\Users\Phil\OldLogs
- name: Unzip gz log
community.windows.win_unzip:
src: C:\Logs\application-error-logs.gz
dest: C:\ExtractedLogs\application-error-logs
# Unzip .zip file, recursively decompresses the contained .gz files and removes all unneeded compressed files after completion.
- name: Recursively decompress GZ files in ApplicationLogs.zip
community.windows.win_unzip:
src: C:\Downloads\ApplicationLogs.zip
dest: C:\Application\Logs
recurse: true
delete_archive: true
- name: Install PSCX
community.windows.win_psmodule:
name: Pscx
state: present
- name: Unzip .7z file which is password encrypted
community.windows.win_unzip:
src: C:\Downloads\ApplicationLogs.7z
dest: C:\Application\Logs
password: abcd
delete_archive: true
返回值
常见的返回值记录在此处,以下是此模块独有的字段
Key |
描述 |
---|---|
提供的目标路径 返回:始终 示例: |
|
模块在任务运行期间是否删除了任何文件 返回:始终 示例: |
|
提供的源路径 返回:始终 示例: |