I would like to exclude a folder from being archived into a tar.gz file. However, I’ve tried multiple options but I haven’t had any luck. Any time I run the archive module, the images directory keeps on getting backed up even though it should be excluded.
`
name: Archiving the Contents of all the websites
archive:
path: ‘{{ item.path }}’
dest: ‘{{ item.dest }}’
owner: centos
group: centos
mode: 0740
format: gz
with_items:
I’ve been looking into similar stuff with ansible. It seems like there is a problem with the archive module in general (as of version 2.4, not sure if its been fixed yet). I saw on their git hub that a pull request that fixes the archive module exclude_path option has been put up, but I don’t think its been merged into the code yet.
The problem has to do with exactly how the items in the exclude_path interact with the items in the path. As far as I can tell it makes exclude_path extremely hard to use and almost useless, but then again I don’t fully understand the problem so maybe I just don’t see the ‘correct’ way to format to work around the issue.
I’ve been trying to think of a work-around that I like for the current tarball I want to create and I stumbled on this hoping to find someone who had already come up with a good work-around.
My leading thoughts are:
try to do it with the shell or command module and the tar command
use a bunch of smaller ansible file copy operations to create a staging directory that looks like what I want and then tar up that
I don’t really like either which is why I was hoping to find a better work-around…
No worries!
I barely check these boards because of the overwhelming amount of ansible posts that fly around here. I can’t even come close to keeping up with all of the different applications and usages that show up and get asked about on these boards.
I’m glad you settled on a work-around while also sorry that we have to do work-arounds for something as common as tar. I had to settle for a work-around for my ansible tar usage as well. Maybe when I get free time I’ll look into the most updated version on git hub and see if it should be fixed or not…
I have the same problem, I want to use ‘exclude_path’ ,but I can’t get it working.
The issue on github is now closed even though the problem remain I think.
Was there any way to make exclusion working as it should, I mean as it is described in the doc ?
tks
name: archiving
archive:
mode : 0755
path: /foo/bar/* # here I added an extra ‘/*’ to make exclude_path working as suggested in the github issue
dest: /foo/baz
exclude_path:
/foo/bar/abc/ # this seems to be excluded ok
/foo/bar/123/*xyz/ # this never worked
async: 1000
poll: 10
tags: zip