Extract an archive in Windows-like systems - Ansible module win_unzip
How to automate the extraction of an example ZIP compressed archive with a text file inside creating the output directory on a Windows-like system with Ansible module win_unzip


How to extract a ZIP compressed archive in Windows-like systems in Ansible?
I’m going to show you a live demo 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
The Best Resources For Ansible
Video Course
Printed Book
eBooks
- Ansible by Examples: 200+ Automation Examples For Linux and Windows System Administrator and DevOps
- Ansible For Windows By Examples: 50+ Automation Examples For Windows System Administrator And DevOps
- Ansible For Linux by Examples: 100+ Automation Examples For Linux System Administrator and DevOps
- Ansible Linux Filesystem By Examples: 40+ Automation Examples on Linux File and Directory Operation for Modern IT Infrastructure
- Ansible For Containers and Kubernetes By Examples: 20+ Automation Examples To Automate Containers, Kubernetes and OpenShift
- Ansible For Security by Examples: 100+ Automation Examples to Automate Security and Verify Compliance for IT Modern Infrastructure
- Ansible Tips and Tricks: 10+ Ansible Examples to Save Time and Automate More Tasks
- Ansible Linux Users & Groups By Examples: 20+ Automation Examples on Linux Users and Groups Operation for Modern IT Infrastructure
- Ansible For PostgreSQL by Examples: 10+ Examples To Automate Your PostgreSQL database
- Ansible For Amazon Web Services AWS By Examples: 10+ Examples To Automate Your AWS Modern Infrastructure
demo
How to extract an archive in Windows-like systems with Ansible Playbook.
code
---
- name: win_unzip module demo
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 }}"
execution
ansible-pilot $ ansible-playbook -i virtualmachines/win/inventory extract\ archive/win_file.yml
PLAY [win_unzip module demo] ***************************************************
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
ansible-pilot $ ansible-playbook -i virtualmachines/win/inventory extract\ archive/win_file.yml
PLAY [win_unzip module demo] ***************************************************
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 $
before execution
after execution
Recap
Now you know how to extract an archive in Windows-like systems with Ansible. Subscribe to the YouTube channel, Medium, Website, Twitter, and Substack to not miss the next episode of the Ansible Pilot.
Academy
Learn the Ansible automation technology with some real-life examples in my
My book Ansible By Examples: 200+ Automation Examples For Linux and Windows System Administrator and DevOps
Donate
Want to keep this project going? Please donate