Ansible unarchive Module: Extract tar, zip, gz Archives (Complete Guide)
By Luca Berton · Published 2024-01-01 · Category: installation
How to use Ansible unarchive module to extract tar.gz, zip, bz2 archives. Deploy from local or remote sources. Complete guide with playbook examples.
Ansible unarchive Module: Extract tar, zip, gz Archives (Complete Guide)
The ansible.builtin.unarchive module unpack compressed archives on remote hosts. This guide covers all common use cases with practical playbook examples.
Extract Local Archive to Remote Host
Extract Remote Archive
Extract with Specific Options
Extract zip File
FAQ
How do I extract a tar.gz file in Ansible?
Use ansible.builtin.unarchive with src (archive path) and dest (target directory). Add remote_src: true if the archive is already on the remote host.
Can Ansible download and extract an archive in one step?
Yes. Set src to an HTTP/HTTPS URL and remote_src: true. Ansible downloads and extracts in one task. Use creates to skip if already extracted.
What archive formats does unarchive support?
Ansible unarchive supports tar, tar.gz, tar.bz2, tar.xz, zip, and gz. The remote host needs the appropriate tools installed (tar, unzip, gzip, bzip2, xz).
Conclusion
The ansible.builtin.unarchive module is a versatile tool for unpack compressed archives on remote hosts. Use the examples above as starting points and adapt them to your infrastructure needs.
Related Articles • Ansible copy Module: Copy Files to Hosts • Ansible get_url: Download Files
Category: installation