delete the older files using Ansible play book

I need to write an ansible script to solve the below requirement. i am trying to write script, few steps i have written but i am having some doubt how to lsit all the files older than 7 days, once we got the list of fies we need to send those files “*.merged” to a specific mail id, below are few steps which I have initiated . not sure that is right or wrong. Request you to suggest the steps.

REQUIREMENT:

  1. monitoring the “*.merged” files older than 7 days and delete those files after sending the list of files to the Mail id

  2. In linux we are using " ls -l /prod/HDOP/data//bigplay.na/yarn/nm/usercache" to display all the Cache Files as ".merged"

  3. we need to find all the files older than 7 days and make a list

  4. Send a mail having list of files which is older than 7 days to XXX@gmail.com on a weekly basis.

5.we need to delete all files older than 7 days ,Once we have sent those file list to XXX@gmail.com

PLAYBOOK:

Pseudo code:

  1. find - to find the specific files, and register the result.
  2. http://docs.ansible.com/ansible/latest/mail_module.html and attach the files from the previous task result
  3. file - to remove the same set of files from 1.

Hello Group Members,

Can some one please look into below ansible codes ,and let me know whether it’s correct or we need to modify anywhere, as I am new to ansible and currently I don’t have access to test the code.

REQUIREMENT:

  1. monitoring the “*.merged” files older than 7 days and delete those files after sending the list of files to the Mail id

  2. In linux we are using " ls -l /prod/HDOP/data//bigplay.na/yarn/nm/usercache" to display all the Cache Files as ".merged"

  3. we need to find all the files older than 7 days and make a list

  4. Send a mail having list of files which is older than 7 days to XXX@gmail.com on a weekly basis.

5.we need to delete all files older than 7 days ,Once we have sent those file list to XXX@gmail.com

PLAYBOOK:

Hi Bibhu

Not sure what you mean by "I don't have access to test the code".
Instead of guessing what might have happened if you ran the playbook,
just run it.

If you are concerned with accidentally removing files, use the
'--check' option for ansible-playbook.
Ansible will report any issues, usually in a easy to understand
fashion so you can fix the code.

Dick

Thank you Dick

Thanks and Regards
Bibhu