# exclude\_path not working on archive module

**URL:** <https://forum.ansible.com/t/exclude-path-not-working-on-archive-module/28736>\
**Category:** Ansible Project\
**Created:** [October 5, 2018, 10:58pm UTC](https://forum.ansible.com/t/exclude-path-not-working-on-archive-module/28736 "2018-10-05T22:58:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![JS11](https://avatars.discourse-cdn.com/v4/letter/j/f17d59/32.png) [@JS11](https://forum.ansible.com/u/JS11)\
**Post date:** [October 5, 2018, 10:58pm UTC](https://forum.ansible.com/t/exclude-path-not-working-on-archive-module/28736/1 "2018-10-05T22:58:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![James\_LeBlanc](https://avatars.discourse-cdn.com/v4/letter/j/96bed5/32.png) [@James\_LeBlanc](https://forum.ansible.com/u/James_LeBlanc)\
**Post date:** [November 9, 2018, 6:52pm UTC](https://forum.ansible.com/t/exclude-path-not-working-on-archive-module/28736/2 "2018-11-09T18:52:38Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![James\_LeBlanc](https://avatars.discourse-cdn.com/v4/letter/j/96bed5/32.png) [@James\_LeBlanc](https://forum.ansible.com/u/James_LeBlanc)\
**Post date:** [November 9, 2018, 7:02pm UTC](https://forum.ansible.com/t/exclude-path-not-working-on-archive-module/28736/3 "2018-11-09T19:02:04Z")

</div>

Here is the github link:  
[https://github.com/ansible/ansible/issues/34316](https://github.com/ansible/ansible/issues/34316)

---

<div class="post-metadata">

**Author:** ![JS11](https://avatars.discourse-cdn.com/v4/letter/j/f17d59/32.png) [@JS11](https://forum.ansible.com/u/JS11)\
**Post date:** [January 21, 2019, 4:37pm UTC](https://forum.ansible.com/t/exclude-path-not-working-on-archive-module/28736/4 "2019-01-21T16:37:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![James\_LeBlanc](https://avatars.discourse-cdn.com/v4/letter/j/96bed5/32.png) [@James\_LeBlanc](https://forum.ansible.com/u/James_LeBlanc)\
**Post date:** [January 21, 2019, 6:46pm UTC](https://forum.ansible.com/t/exclude-path-not-working-on-archive-module/28736/5 "2019-01-21T18:46:57Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![Nic\_H](https://avatars.discourse-cdn.com/v4/letter/n/d9b06d/32.png) [@Nic\_H](https://forum.ansible.com/u/Nic_H)\
**Post date:** [December 28, 2020, 2:38am UTC](https://forum.ansible.com/t/exclude-path-not-working-on-archive-module/28736/6 "2020-12-28T02:38:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Nic\_H](https://avatars.discourse-cdn.com/v4/letter/n/d9b06d/32.png) [@Nic\_H](https://forum.ansible.com/u/Nic_H)\
**Post date:** [December 28, 2020, 6:17pm UTC](https://forum.ansible.com/t/exclude-path-not-working-on-archive-module/28736/7 "2020-12-28T18:17:39Z")

</div>

seems like the issue was closed because the module moved to community , although nothing is fixed .

[https://github.com/ansible/ansible/issues/34316](https://github.com/ansible/ansible/issues/34316)

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
