

Archive Multiple files from multiple Directories with few exclusions.How to Create a bz2 archive with Ansible archive module.How to Create a zip archive with Ansible archive module.Remove the Source files after adding to the archive and compressed.Compressing the Directory with tar and gz.Can produce gzip, bzip2, lzma and zip compressed files or archives.Requires lzma or backports.lzma if using xz format.Requires tarfile, zipfile, gzip and bzip2 packages on target host.Source files can be deleted after archival by specifying remove=True.It will not copy the source file from the local system to the target before archiving.By default, it assumes the source file you are trying to compress does exist.This command is the opposite of unarchive command of ansible.How to Unarchive the files with Ansible – Additional.Example 8: Ansible archive multiples files with loop – multiple single files.Example 7: Compressing and Archiving multiple files Ansible archive.Example 6: Create a BZIP archive – File and Directory.Example 5: Create a ZIP file archive – File and Directory.

/tar-files-5878e7d15f9b584db3cf9bde.png)

Example 4: Remove the Source files after archiving.Example 3: Compress the file – Default File Compress format.Example 2:Compressing the Directory with tar and gz.Example1: Compressing the Directory with TAR.The syntax for tar is a bit more verbose than what we’ve experienced thus far. We could delve into piping the output from tar into gzip to create a compressed tarball, but tar makes things easy by allowing us to pass in an argument to tell it to use gzip for compression. Because it takes multiple files and creates a single “tape archive”, we can then use gzip to compress the individual file that is created. In fact, compressing multiple files with gzip is impossible because gzip doesn’t have any understanding of the file system. $ touch /tmp/dir-of-files/ įor gzip, things aren’t so easy.
