unarchive – Unpacks an archive after (optionally) copying it from the local machine.
unarchive – Unpacks an archive after (optionally) copying it from the local machine.
New in version 1.4.
Synopsis
- The
unarchive
module unpacks 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. - For Windows targets, use the win_unzip module instead.
- If checksum validation is desired, use get_url or uri instead to fetch the file and set
remote_src=yes
.
Parameters
Parameter | Choices/Defaults | Comments |
---|---|---|
attributes - added in 2.3 |
Attributes the file or directory should have. To get supported flags look at the man page for chattr on the target system. This string should contain the attributes in the same order as the one displayed by lsattr.
| |
copy boolean |
|
If true, the file is copied from local 'master' to the target machine, otherwise, the plugin will look for src archive at the target machine. This option has been deprecated in favor of This option is mutually exclusive with |
creates - added in 1.6 |
If the specified absolute path (file or directory) already exists, this step will not be run. | |
decrypt boolean added in 2.4 |
|
This option controls the autodecryption of source files using vault. |
dest - / required |
Remote absolute path where the archive should be unpacked. | |
exclude - added in 2.1 |
List the directory and file entries that you would like to exclude from the unarchive action. | |
extra_opts - added in 2.1 |
Default: "" |
Specify additional options by passing in an array. |
group - |
Name of the group that should own the file/directory, as would be fed to chown. | |
keep_newer boolean added in 2.1 |
|
Do not replace existing files that are newer than files from the archive. |
list_files boolean added in 2.0 |
|
If set to True, return the list of files that are contained in the tarball. |
mode - |
Mode the file or directory should be. For those used to /usr/bin/chmod remember that modes are actually octal numbers. You must either add a leading zero so that Ansible's YAML parser knows it is an octal number (like | |
owner - |
Name of the user that should own the file/directory, as would be fed to chown. | |
remote_src boolean added in 2.2 |
|
Set to This option is mutually exclusive with |
selevel - |
Default: "s0" |
Level part of the SELinux file context. This is the MLS/MCS attribute, sometimes known as the |
serole - |
Role part of SELinux file context, | |
setype - |
Type part of SELinux file context, | |
seuser - |
User part of SELinux file context. Will default to system policy, if applicable. If set to | |
src - / required |
If If | |
unsafe_writes boolean added in 2.2 |
|
By default this module uses atomic operations to prevent data corruption or inconsistent reads from the target files, but sometimes systems are configured or just broken in ways that prevent this. One example is docker mounted files, which cannot be updated atomically from inside the container and can only be written in an unsafe manner. This option allows Ansible to fall back to unsafe methods of updating files when atomic operations fail (however, it doesn't force Ansible to perform unsafe writes). IMPORTANT! Unsafe writes are subject to race conditions and can lead to data corruption. |
validate_certs boolean added in 2.2 |
|
This only applies if using a https URL as the source of the file. This should only set to Prior to 2.2 the code worked as if this was set to |
Notes
Note
- Requires
gtar
/unzip
command on target host. - Can handle .zip files using
unzip
as well as .tar, .tar.gz, .tar.bz2 and .tar.xz files usinggtar
. - 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.
- For Windows targets, use the win_unzip module instead.
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
© 2012–2018 Michael DeHaan
© 2018–2019 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/2.7/modules/unarchive_module.html