# excludes not work as expected with find module in ansible playbook

**URL:** <https://forum.ansible.com/t/excludes-not-work-as-expected-with-find-module-in-ansible-playbook/34431>\
**Category:** Ansible Project\
**Created:** [January 13, 2021, 2:58pm UTC](https://forum.ansible.com/t/excludes-not-work-as-expected-with-find-module-in-ansible-playbook/34431 "2021-01-13T14:58:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nithin\_Subbaraj](https://avatars.discourse-cdn.com/v4/letter/n/e480ec/32.png) [@Nithin\_Subbaraj](https://forum.ansible.com/u/Nithin_Subbaraj)\
**Post date:** [January 13, 2021, 2:58pm UTC](https://forum.ansible.com/t/excludes-not-work-as-expected-with-find-module-in-ansible-playbook/34431/1 "2021-01-13T14:58:11Z")

</div>

I have created an ansible playbook which finds files older than 7 days and zips the files.

Also trying to exclude files from particular directory but not able to find.

I am not able to the exclude the files under sub directory ,it is also getting zipped  
I am able to successfully exclude the already zipped files but not a sub directory under the path

using excludes in find module for compressing files older than 7 days

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [January 13, 2021, 3:08pm UTC](https://forum.ansible.com/t/excludes-not-work-as-expected-with-find-module-in-ansible-playbook/34431/2 "2021-01-13T15:08:16Z")

</div>

> I have created an ansible playbook which finds files older than 7 days and zips the files.  
> Also trying to exclude files from particular directory but not able to find.
> 
> I am not able to the exclude the files under sub directory ,it is also getting zipped  
> I am able to successfully exclude the already zipped files but not a sub directory under the path
> 
> using excludes in find module for compressing files older than 7 days

Please share your playbook.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Nithin\_Subbaraj](https://avatars.discourse-cdn.com/v4/letter/n/e480ec/32.png) [@Nithin\_Subbaraj](https://forum.ansible.com/u/Nithin_Subbaraj)\
**Post date:** [January 13, 2021, 3:20pm UTC](https://forum.ansible.com/t/excludes-not-work-as-expected-with-find-module-in-ansible-playbook/34431/3 "2021-01-13T15:20:31Z")

</div>

Hi Racke,

Please find the below playbook details the username and path are test paths

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [January 13, 2021, 3:30pm UTC](https://forum.ansible.com/t/excludes-not-work-as-expected-with-find-module-in-ansible-playbook/34431/4 "2021-01-13T15:30:10Z")

</div>

> Hi Racke,
> 
> Please find the below playbook details the username and path are test paths
> 
> ---  
> - name: Ansible archive Examples  
> hosts: all  
> tasks:
> 
> ```
> \- name : Find files ending with extensions
> become: true
> find:
> paths:
> \- /home/nsubbaraj/replicate/vol/gunnsc01/prod/scoreout
> recurse: yes
> file\_type: any
> excludes:
> \- &#39;\*\.gz&#39;
> \- /home/nsubbaraj/replicate/vol/gunnsc01/prod/scoreout/delete
> depth: 4
> age: 7d
> age\_stamp: mtime
> register: output
> 
> \- name: archive the files
> become: yes
> archive:
> remove: yes
> path: &quot;\{\{ item\.path \}\}&quot;
> dest: &quot;\{\{ item\.path \}\}\-\{\{ansible\_date\_time\.date\.replace\(&#39;\-&#39;,&#39;&#39;\)\}\}\.gz&quot;
> format: zip
> with\_items: &quot;\{\{ output\.files \}\}&quot;
> 
> ```
> 
> ##############################
> 
> I am able to exclude the gzip files but not the delete directory files under  
> /home/nsubbaraj/replicate/vol/gunnsc01/prod/scoreout/

I think the values for "excludes" need to be relative to the path(s), so try "delete"  
instead of "/home/nsubbaraj/replicate/vol/gunnsc01/prod/scoreout/delete".

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Nithin\_Subbaraj](https://avatars.discourse-cdn.com/v4/letter/n/e480ec/32.png) [@Nithin\_Subbaraj](https://forum.ansible.com/u/Nithin_Subbaraj)\
**Post date:** [January 13, 2021, 3:38pm UTC](https://forum.ansible.com/t/excludes-not-work-as-expected-with-find-module-in-ansible-playbook/34431/5 "2021-01-13T15:38:37Z")

</div>

Thanks ,I had tried already and tried again but no luck .

I tried with
