0

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

1 Answers1

0

Try this:

  mail:
    host: smtp.your-domain
    port: 25
    to: "<your email>"
    subject: "subject line"
    body: "your message {{ file_date}} "
  ignore_errors: yes
  when: file_date.stat.exists```
driverA
  • 1
  • 1