community.general.archive – Creates a compressed archive of one or more files or trees¶
Note
This plugin is part of the community.general collection (version 1.3.6).
To install it use: ansible-galaxy collection install community.general
.
To use it in a playbook, specify: community.general.archive
.
Synopsis¶
Creates or extends an archive.
The source and archive are on the remote host, and the archive is not copied to the local host.
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
- ansible.builtin.unarchive
The official documentation on the ansible.builtin.unarchive module.
Examples¶
- name: Compress directory /path/to/foo/ into /path/to/foo.tgz
community.general.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
community.general.archive:
path: /path/to/foo
remove: yes
- name: Create a zip archive of /path/to/foo
community.general.archive:
path: /path/to/foo
format: zip
- name: Create a bz2 archive of multiple files, rooted at /path
community.general.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
community.general.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
community.general.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)
community.general.archive:
path: /path/to/foo/single.file
dest: /path/file.gz
format: gz
- name: Create a tar.gz archive of a single file.
community.general.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:
Authors¶
Ben Doherty (@bendoh)