exclude_path not working on archive module

1,322 views
Skip to first unread message

JS

unread,
Oct 5, 2018, 6:58:25 PM10/5/18
to Ansible Project
Hello!

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
:
 
- { path: '{{ websites_path }}/{{ site01 }}', dest: '{{ remote_backup_path }}/{{ date_time }}/{{ site01 }}/{{ site01 }}.tar.gz', exclude_path:'/var/www/html/abcd.com/test/images' }
 
- { path: '{{ websites_path }}/{{ site02 }}', dest: '{{ remote_backup_path }}/{{ date_time }}/{{ site02 }}/{{ site02 }}.tar.gz' }



I've tried this as well:

- name: Archiving the Contents of all the websites
  archive
:
    path
: '{{ item.path }}'
    dest
: '{{ item.dest }}'
    exclude_path
:
   
- /var/www/html/abcd.com/test/images
    owner
: centos
   
group: centos
    mode
: 0740
    format
: gz
  with_items
:
 
- { path: '{{ websites_path }}/{{ site01 }}', dest: '{{ remote_backup_path }}/{{ date_time }}/{{ site01 }}/{{ site01 }}.tar.gz', }
 
- { path: '{{ websites_path }}/{{ site02 }}', dest: '{{ remote_backup_path }}/{{ date_time }}/{{ site02 }}/{{ site02 }}.tar.gz' }



Would someone be able to advise me on how I can exclude a particular directory from being archived?

Regards
JS

James LeBlanc

unread,
Nov 9, 2018, 1:52:38 PM11/9/18
to Ansible Project
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....

James LeBlanc

unread,
Nov 9, 2018, 2:02:05 PM11/9/18
to Ansible Project

JS

unread,
Jan 21, 2019, 11:37:19 AM1/21/19
to Ansible Project
Hi James

Apologies, I thought I'd already replied to your message!

I've tried the latest version of ansible - still haven't had much luck with the archive module and exclude_path.

I've just restored to using the shell module for now to tar it up manually, but it's not great!

Regards
JS

James LeBlanc

unread,
Jan 21, 2019, 1:46:57 PM1/21/19
to Ansible Project
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...

Nick-H

unread,
Dec 27, 2020, 9:38:12 PM12/27/20
to Ansible Project
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

Nick-H

unread,
Dec 28, 2020, 1:17:39 PM12/28/20
to Ansible Project
seems like the issue was closed because the module moved to community , although nothing is fixed .

Here what I do , without success :

- 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 




Reply all
Reply to author
Forward
0 new messages