community.windows.win_unzip (2.2.0) — module

Unzips compressed files and archives on the Windows node

Authors: Phil Schwartz (@schwartzmx)

Install collection

Install with ansible-galaxy collection install community.windows:==2.2.0


Add to requirements.yml

  collections:
    - name: community.windows
      version: 2.2.0

Description

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 M(ansible.builtin.unarchive) module instead.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Unzip gz log
  community.windows.win_unzip:
    src: C:\Logs\application-error-logs.gz
    dest: C:\ExtractedLogs\application-error-logs
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# 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
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Install PSCX
  community.windows.win_psmodule:
    name: Pscx
    state: present
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- 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

Inputs

    
src:
    description:
    - File to be unzipped (provide absolute path).
    required: true
    type: path

dest:
    description:
    - Destination of zip file (provide absolute path of directory). If it does not exist,
      the directory will be created.
    required: true
    type: path

creates:
    description:
    - If this file or directory exists the specified src will not be extracted.
    type: path

recurse:
    default: false
    description:
    - Recursively expand zipped files within the src file.
    - Setting to a value of C(yes) requires the PSCX module to be installed.
    type: bool

password:
    description:
    - If a zip file is encrypted with password.
    - Passing a value to a password parameter requires the PSCX module to be installed.

delete_archive:
    aliases:
    - rm
    default: false
    description:
    - Remove the zip file, after unzipping.
    type: bool

Outputs

dest:
  description: The provided destination path
  returned: always
  sample: C:\ExtractedLogs\application-error-logs
  type: str
removed:
  description: Whether the module did remove any files during task run
  returned: always
  sample: true
  type: bool
src:
  description: The provided source path
  returned: always
  sample: C:\Logs\application-error-logs.gz
  type: str

See also