unarchive – Unpacks an archive after (optionally) copying it from the local machine¶
Synopsis¶
- The
unarchive
module unpacks an archive. It will not unpack a compressed file that does not contain an 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 already exists on the target. - If checksum validation is desired, use get_url or uri instead to fetch the file and set
remote_src=yes
. - For Windows targets, use the win_unzip module instead.
Parameters¶
Notes¶
Note
- Requires
zipinfo
andgtar
/unzip
command on target host. - Can handle .zip files using
unzip
as well as .tar, .tar.gz, .tar.bz2 and .tar.xz files usinggtar
. - Does not handle .gz files, .bz2 files or .xz files that do not contain a .tar archive.
- Uses gtar’s
--diff
arg to calculate if changed or not. If thisarg
is not supported, it will always unpack the archive. - Existing files/directories in the destination which are not in the archive are not touched. This is the same behavior as a normal archive extraction.
- Existing files/directories in the destination which are not in the archive are ignored for purposes of deciding if the archive should be unpacked or not.
See Also¶
See also
- archive – Creates a compressed archive of one or more files or trees
- The official documentation on the archive module.
- iso_extract – Extract files from an ISO image
- The official documentation on the iso_extract module.
- win_unzip – Unzips compressed files and archives on the Windows node
- The official documentation on the win_unzip module.
Examples¶
- name: Extract foo.tgz into /var/lib/foo
unarchive:
src: foo.tgz
dest: /var/lib/foo
- name: Unarchive a file that is already on the remote machine
unarchive:
src: /tmp/foo.zip
dest: /usr/local/bin
remote_src: yes
- name: Unarchive a file that needs to be downloaded (added in 2.0)
unarchive:
src: https://example.com/example.zip
dest: /usr/local/bin
remote_src: yes
- name: Unarchive a file with extra options
unarchive:
src: /tmp/foo.zip
dest: /usr/local/bin
extra_opts:
- --transform
- s/^xxx/yyy/
Status¶
- This module is not guaranteed to have a backwards compatible interface. [preview]
- This module is maintained by the Ansible Core Team. [core]
Red Hat Support¶
More information about Red Hat’s support of this module is available from this Red Hat Knowledge Base article.
Authors¶
- Michael DeHaan
Hint
If you notice any issues in this documentation, you can edit this document to improve it.