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 X...@gmail.com on a weekly basis.
PLAYBOOK:
---
- hosts: All
user :
sudo: yes
Connection : SSH
gather-facts : yes
tasks:
- name: list the cache files
find:
paths= "/prod/HDOP/data/*" age="8d" recurse=yes
patterns: *.merged
**** Not sure how to list all the files and send those list to specific mail id*************
**** Then Need to delete those files which is older than 7days ****************
--
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.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/e5300906-4149-413f-85a0-76ebbba73212%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
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 X...@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 X...@gmail.com
PLAYBOOK:
---
- hosts: All
user :
sudo: yes
Connection : SSH
gather-facts : yes
tasks:
- name: list the cache files
find:
paths= "/prod/HDOP/data/*" age="8d" recurse=yes
patterns: "*.merged"
register: files_matched
- debug:
msg: "{{ files_matched. stdout_lines }}"
- name: Send a success email
mail:
host: ( Simple Mail Transfer Protocol (SMTP) name)
port: xxxxxx
username: 28283aeebd83616c6
password: 0432eb4224e406
to: xx...@xxxx.com
subject: Cleaning Yarn Cache
body: "List of files {{ files_matched. stdout_lines }}"
- name : clear more than 7 days older cache file
files:
path={{ item.path }}
state=absent
with_items: "{{ files_matched. stdout_lines }}"