Documentation

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..

Options

parameter required default choices comments
attributes
(added in 2.3)
no None
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.

aliases: attr
copy
no yes
  • yes
  • no
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 remote_src
This option is mutually exclusive with remote_src.
creates
(added in 1.6)
no
a filename, when it already exists, this step will not be run.
dest
yes
Remote absolute path where the archive should be unpacked
exclude
(added in 2.1)
no
List the directory and file entries that you would like to exclude from the unarchive action.
extra_opts
(added in 2.1)
no
Specify additional options by passing in an array.
group
no
Name of the group that should own the file/directory, as would be fed to chown.
keep_newer
(added in 2.1)
no
Do not replace existing files that are newer than files from the archive.
list_files
(added in 2.0)
no no
  • yes
  • no
If set to True, return the list of files that are contained in the tarball.
mode
no
Mode the file or directory should be. For those used to /usr/bin/chmod remember that modes are actually octal numbers (like 0644). Leaving off the leading zero will likely have unexpected results. As of version 1.8, the mode may be specified as a symbolic mode (for example, u+rwx or u=rw,g=r,o=r).
owner
no
Name of the user that should own the file/directory, as would be fed to chown.
remote_src
(added in 2.2)
no no
  • yes
  • no
Set to yes to indicate the archived file is already on the remote system and not local to the Ansible controller.
This option is mutually exclusive with copy.
selevel
no s0
Level part of the SELinux file context. This is the MLS/MCS attribute, sometimes known as the range. _default feature works as for seuser.
serole
no
Role part of SELinux file context, _default feature works as for seuser.
setype
no
Type part of SELinux file context, _default feature works as for seuser.
seuser
no
User part of SELinux file context. Will default to system policy, if applicable. If set to _default, it will use the user portion of the policy if available.
src
yes
If remote_src=no (default), local path to archive file to copy to the target server; can be absolute or relative. If remote_src=yes, path on the target server to existing archive file to unpack.
If remote_src=yes and src contains ://, the remote machine will download the file from the url first. (version_added 2.0). This is only for simple cases, for full download support look at the get_url module.
unsafe_writes
(added in 2.2)
no
Normally this module uses atomic operations to prevent data corruption or inconsistent reads from the target files, sometimes systems are configured or just broken in ways that prevent this. One example are docker mounted files, they cannot be updated atomically and can only be done in an unsafe manner.
This boolean option allows ansible to fall back to unsafe methods of updating files for those cases in which you do not have any other choice. Be aware that this is subject to race conditions and can lead to data corruption.
validate_certs
(added in 2.2)
no yes
  • yes
  • no
This only applies if using a https url as the source of the file.
This should only set to no used on personally controlled sites using self-signed cer
Prior to 2.2 the code worked as if this was set to yes.

Examples

# Example from Ansible Playbooks
- unarchive:
    src: foo.tgz
    dest: /var/lib/foo

# Unarchive a file that is already on the remote machine
- unarchive:
    src: /tmp/foo.zip
    dest: /usr/local/bin
    remote_src: True

# 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: True

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 using gtar
  • uses gtar’s --diff arg to calculate if changed or not. If this arg 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

Status

This module is flagged as preview which means that it is not guaranteed to have a backwards compatible interface.

Support

This module is maintained by those with core commit privileges

For more information on what this means please read Module Support

For help in developing on modules, should you be so inclined, please read Community Information & Contributing, Helping Testing PRs and Developing Modules.