AnsiblePilot — Master Ansible Automation
AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,100 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.
Popular Topics
About Luca Berton
Luca Berton is an Ansible automation expert, author of "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example" published by Apress, and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.
Ansible win_unzip Module: Extract ZIP Archives on Windows (Guide) — Video Tutorial
How to extract ZIP archives on Windows with Ansible win_unzip module (community.windows.win_unzip). Unzip files, extract to directory. Practical YAML playbook examples.
What You'll Learn
- How to extract a ZIP compressed archive in Windows-like systems in Ansible?
- Ansible extracts an archive in Windows-like systems
- Parameters
- Links
- code
- execution
- NOT idempotent
- before execution
- after execution
- Conclusion
Full Tutorial Content
How to extract a ZIP compressed archive in Windows-like systems in Ansible?
I'm going to show you a live Playbook and some simple Ansible code.
I'm Luca Berton and welcome to today's episode of Ansible Pilot.
Ansible extracts an archive in Windows-like systems
- `community.windows.win_unzip`
- Unzips compressed files and archives on the Windows node
Today we're talking about the Ansible module `win_unzip`.
The full name is `community.windows.win_unzip`, which means that is part of modules maintained by the community for Windows target hosts.
It unzips compressed files and archives on the Windows node.
It supports .zip files natively and can handle also other 7zip formats when combined with the Powershell Community Extensions (PSCX) module.
For Linux targets, use the `ansible.builtin.unarchive` module.
Parameters
- src string - remote path
- dest string - remote path
- password string - password (require PSCX)
- recurse boolean - no/yes - recursively expand zip files (require PSCX)
The parameters of module `win_unzip`.
The only mandatory parameters are "src" and "dest" which are the source and destination paths.
The "src" is quite special because is supposed to be a remote path on Windows-like systems.
The following two parameters require Powershell Community Extensions (PSCX) module.
You could specify the encryption password to expand the archive in the "password" parameter.
You could recursively expand zip files inside an archive enabling the "recurse" boolean.
Links
- [Ansible module win_unzip](https://docs.ansible.com/ansible/latest/collections/community/windows/win_unzip_module.html)
## Playbook
How to extract an archive in Windows-like systems with Ansible Playbook.
code
```yaml
---
- name: win_unzip module Playbook
hosts: all
become: false
vars:
mysrc: 'C:\Users\vagrant\Desktop\example.zip'
mydest: 'C:\Users\vagrant\Desktop\output'
tasks:
- name: extract archive
community.windows.win_unzip:
src: "{{ mysrc }}"
dest: "{{ mydest }}"
```
[code with ❤️ in GitHub](https://github.com/lucab85/ansible-pilot/)
execution
```bash
ansible-pilot $ ansible-playbook -i virtualmachines/win/inventory extract\ archive/win_file.yml
PLAY [win_unzip module Playbook] ***************************************************
TASK [Gathering Facts] *********************************************************
ok: [WindowsServer]
TASK [extract archive] *********************************************************
changed: [WindowsServer]
PLAY RECAP *********************************************************************
WindowsServer : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
ansible-pilot $
```
NOT idempotent
```bash
ansible-pilot $ ansible-playbook -i virtualmachines/win/inventory extract\ archive/win_file.yml
PLAY [win_unzip module Playbook] ***************************************************
TASK [Gathering Facts] ********************************************
About This Tutorial
- Author: Luca Berton
- Difficulty: Beginner
- Read time: 4 min
- Category: installation
Read the full written article: Ansible win_unzip Module: Extract ZIP Archives on Windows (Guide)
Related Video Tutorials
- Ansible unarchive Module: Extract tar.gz, zip Archives on Remote Hosts — How to extract archives with Ansible unarchive module (ansible.builtin.unarchive). Extract tar.gz, zip, bz2 from local or remote URLs. Practical YAML playbook examples.
- Ansible win_file Module: Create Directory on Windows Hosts (Guide) — How to create directories on Windows with Ansible win_file module (ansible.windows.win_file). Set paths, manage folders, handle permissions. Practical YAML playbook examples for Windows automation.
- Ansible win_file Module: Create & Manage Files on Windows (Guide) — How to create and manage files on Windows with Ansible win_file module (ansible.windows.win_file). Create files, directories, symlinks on Windows. Practical YAML playbook examples.
- Ansible Set File Permissions 755: chmod with file Module Guide — How to set file permissions with Ansible file module. Add execute permission (755, 644, 600), manage ownership, and apply permissions recursively.
- Add Windows Registry on Windows-like systems - Ansible module win_regedit — Learn how to use Ansible win_regedit module to add, change, or remove Windows registry key-values efficiently and accurately with simple Ansible code examples.
- Ansible Backup Windows 10/11/2019/2022: win_robocopy Playbook (Guide) — How to automate the backup synchronization of an “examples” folder to “examples-backup” on Windows using RoboCopy with Ansible module win_robocopy.