Score:0

Ansible file check and send mail

mq flag

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: [email protected]
      subject: info file
      body: ' "{{ file_data }}" '
    when: file_data.stat.exists
in flag
IMO Ansible is not a suitable tool for this job.
zaca011 avatar
mq flag
ok, this can be done in several ways. But I want to try using Ansible
Score:0
pm flag

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```
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.