Unzips compressed files and archives on the Windows node
- Unzips compressed files and archives.
- Supports .zip files natively.
- Supports other formats supported by the Powershell Community Extensions (PSCX) module (basically everything 7zip supports).
- For non-Windows targets, use the :ref:`ansible.builtin.unarchive <ansible.builtin.unarchive_module>` module instead.
The below requirements are needed on the host that executes this module.
- PSCX
Note
- This module is not really idempotent, it will extract the archive every time, and report a change.
- For extracting any compression types other than .zip, the PowerShellCommunityExtensions (PSCX) Module is required. This module (in conjunction with PSCX) has the ability to recursively unzip files within the src zip file provided and also functionality for many other compression types. If the destination directory does not exist, it will be created before unzipping the file. Specifying rm parameter will force removal of the src file after extraction.
.. seealso:: :ref:`ansible.builtin.unarchive_module` The official documentation on the **ansible.builtin.unarchive** module.
# 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: yes
delete_archive: yes
- 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: yes
Common return values are documented here, the following are the fields unique to this module:
- Phil Schwartz (@schwartzmx)