I am trying to create file check using ansible . basically in specific folder every day some job copy some files. I want to receive an email if there are no new files.
I try something like this :
---
- name: Check if file exist and send mail
hosts: localhost
tasks:
- name: File
stat:
path: "/home/backup/"
file_type: directory
age: 1d
register: file_date
- mail:
host: mailserver.example.com
port: 587
to: mymail@example.com
subject: info file
body: ' "{{ file_data }}" '
when: file_data.stat.exists