Ansible comprobar archivos y enviar correo

Ansible comprobar archivos y enviar correo

Estoy intentando crear una verificación de archivos usando ansible. Básicamente, en una carpeta específica todos los días, algún trabajo copia algunos archivos. Quiero recibir un correo electrónico si no hay archivos nuevos.

Intento algo como esto:

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

Respuesta1

Prueba esto:

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

información relacionada