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

関連情報