Ansible 文件檢查並發送郵件

Ansible 文件檢查並發送郵件

我正在嘗試使用 ansible 建立文件檢查。基本上每天都有一些工作在特定資料夾中複製一些文件。如果沒有新文件,我希望收到一封電子郵件。

我嘗試這樣的事情:

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

答案1

嘗試這個:

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

相關內容