Javatpoint Logo
Javatpoint Logo

Ansible Unarchive

Ansible unarchive module is used to unpack or uncompressed the files from an archive file such as zip, tar, tar.gz. It can optionally copy the files to the remote server before uncompressing them.

The unarchive module uses the basic unzip and tar -xvf command-line tools to operate. So the target server must have installed these commands. Since most of the *nix distributions are in-built these tools. Here are some essential points of Ansible unarchive, such as:

  • It requires zipinfo and gtar/unzip command on the target remote host.
  • You can handle .zip files using unzip and .tar, .tar.gz, .tar.bz2, .tar.xz files using gtar.
  • It does not handle .gz, .bz2, .xz files that not contain a .tar archive.
  • It uses gtar --diff arg to calculate if changed or not. If --diff arg is not supported, it will always unpack the archive.
  • By default, it will copy the source file from the local system to the target before unpacking.
  • Set remote_src=yes to unpack an archive which is already existing on the target.
  • If checksum validation is desired, use get_url or Uri instead to fetch the file and set remote_src=yes.
  • Use the win_unzip module for windows targets.
  • We can not touch the Existing files or directories in the destination, which are not in the archive.
  • Existing files or directories in the destination which are not in the archive are ignored to decide if the archive should be unpacked or not.

Why Use Unarchive Module

The Ansible Unarchive module is useful for moving large files and folders across host machines.

For example, if you have a bunch of NGINX configuration files, you can use the unarchive command to download a zipped folder from a URL and unzip it.

Examples

1. Extract foo.tgz into /var/lib/foo as shown in the following code, such as:

2. To unarchive a file that is already on the remote machine:

3. To unarchive a file that needs to be downloaded:

4. To unarchive a file with extra options


Next TopicAnsible Pip




Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA