excludes not work as expected with find module in ansible playbook

51 views
Skip to first unread message

Nithin Subbaraj

unread,
Jan 13, 2021, 9:58:11 AM1/13/21
to Ansible Project

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

Stefan Hornburg (Racke)

unread,
Jan 13, 2021, 10:08:41 AM1/13/21
to ansible...@googlegroups.com
Please share your playbook.

Regards
Racke

>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/0378a412-1a74-48d2-875a-45ccff472a8cn%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/0378a412-1a74-48d2-875a-45ccff472a8cn%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

OpenPGP_signature

Nithin Subbaraj

unread,
Jan 13, 2021, 10:20:31 AM1/13/21
to Ansible Project
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:
       - '*.gz'
       - /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: "{{ item.path }}"
        dest: "{{ item.path }}-{{ansible_date_time.date.replace('-','')}}.gz"
        format: zip
      with_items: "{{ output.files }}"

##############################

I am able to exclude the gzip files but not the delete directory files under /home/nsubbaraj/replicate/vol/gunnsc01/prod/scoreout/

Stefan Hornburg (Racke)

unread,
Jan 13, 2021, 10:30:38 AM1/13/21
to ansible...@googlegroups.com
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
Racke

>
> On Wednesday, 13 January 2021 at 20:38:41 UTC+5:30 brae...@gmail.com wrote:
>
> On 1/13/21 3:58 PM, Nithin Subbaraj wrote:
> >
> > 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
> Racke
>
> >
> > --
> > You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> > To unsubscribe from this group and stop receiving emails from it, send an email to
> > ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> > To view this discussion on the web visit
> > https://groups.google.com/d/msgid/ansible-project/0378a412-1a74-48d2-875a-45ccff472a8cn%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/0378a412-1a74-48d2-875a-45ccff472a8cn%40googlegroups.com>
> >
> <https://groups.google.com/d/msgid/ansible-project/0378a412-1a74-48d2-875a-45ccff472a8cn%40googlegroups.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/msgid/ansible-project/0378a412-1a74-48d2-875a-45ccff472a8cn%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>
>
>
> --
> Ecommerce and Linux consulting + Perl and web application programming.
> Debian and Sympa administration. Provisioning with Ansible.
>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/8882fa97-8657-486e-99a3-fbd7a5e964d2n%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/8882fa97-8657-486e-99a3-fbd7a5e964d2n%40googlegroups.com?utm_medium=email&utm_source=footer>.
OpenPGP_signature

Nithin Subbaraj

unread,
Jan 13, 2021, 10:38:37 AM1/13/21
to Ansible Project
Thanks ,I had tried already and tried again but no luck .

I tried with

################
 excludes:
       - '*.gz'
       - 'delete'


 excludes:
       - '*.gz'
       - delete   

excludes:
       - '*.gz'
       - "delete"


################

I also checked with other subdirectory other than directory delete if it could clash with keyword like nitest but still not excluding it


Thanks and regards,
Nithin Subbaraj
Reply all
Reply to author
Forward
0 new messages