Ansible-Dateiprüfung und E-Mail senden

Ansible-Dateiprüfung und E-Mail senden

Ich versuche, mit Ansible eine Dateiprüfung zu erstellen. Grundsätzlich werden jeden Tag in einem bestimmten Ordner einige Dateien kopiert. Ich möchte eine E-Mail erhalten, wenn keine neuen Dateien vorhanden sind.

Ich versuche so etwas:

---
- 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: [email protected]
      subject: info file
      body: ' "{{ file_data }}" '
    when: file_data.stat.exists

Antwort1

Versuche dies:

  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```

verwandte Informationen