archive – Creates a compressed archive of one or more files or trees¶
Synopsis¶
Packs an archive.
It is the opposite of unarchive.
By default, it assumes the compression source exists on the target.
It will not copy the source file from the local system to the target before archiving.
Source files can be deleted after archival by specifying remove=True.
Parameters¶
Notes¶
Note
Requires tarfile, zipfile, gzip and bzip2 packages on target host.
Requires lzma or backports.lzma if using xz format.
Can produce gzip, bzip2, lzma and zip compressed files or archives.
See Also¶
See also
- unarchive – Unpacks an archive after (optionally) copying it from the local machine
The official documentation on the unarchive module.
Examples¶
- name: Compress directory /path/to/foo/ into /path/to/foo.tgz
archive:
path: /path/to/foo
dest: /path/to/foo.tgz
- name: Compress regular file /path/to/foo into /path/to/foo.gz and remove it
archive:
path: /path/to/foo
remove: yes
- name: Create a zip archive of /path/to/foo
archive:
path: /path/to/foo
format: zip
- name: Create a bz2 archive of multiple files, rooted at /path
archive:
path:
- /path/to/foo
- /path/wong/foo
dest: /path/file.tar.bz2
format: bz2
- name: Create a bz2 archive of a globbed path, while excluding specific dirnames
archive:
path:
- /path/to/foo/*
dest: /path/file.tar.bz2
exclude_path:
- /path/to/foo/bar
- /path/to/foo/baz
format: bz2
- name: Create a bz2 archive of a globbed path, while excluding a glob of dirnames
archive:
path:
- /path/to/foo/*
dest: /path/file.tar.bz2
exclude_path:
- /path/to/foo/ba*
format: bz2
- name: Use gzip to compress a single archive (i.e don't archive it first with tar)
archive:
path: /path/to/foo/single.file
dest: /path/file.gz
format: gz
- name: Create a tar.gz archive of a single file.
archive:
path: /path/to/foo/single.file
dest: /path/file.tar.gz
format: gz
force_archive: true
Return Values¶
Common return values are documented here, the following are the fields unique to this module:
Status¶
This module is not guaranteed to have a backwards compatible interface. [preview]
This module is maintained by the Ansible Community. [community]
Authors¶
Ben Doherty (@bendoh)
Hint
If you notice any issues in this documentation, you can edit this document to improve it.