EvoBSD/roles/base/tasks/mail.yml

44 lines
1018 B
YAML

---
- name: "Fetch rc.local content"
ansible.builtin.command: "grep -v '^#' /etc/rc.local"
check_mode: false
register: rclocal_content
failed_when: false
changed_when: false
tags:
- alerting
- name: "Configure rc.local"
ansible.builtin.lineinfile:
path: /etc/rc.local
line:
'date | mail -s "boot/reboot of $(hostname -s)" {{ general_alert_email }}'
insertbefore: 'echo'
mode: "0640"
create: true
when:
- not (rclocal_content.stdout
| regex_search('date \| mail -s (\"|\')boot/reboot of \$\(hostname -s\)'))
tags:
- alerting
- name: "Delete rc.local entry of boot/reboot not precising hostname"
ansible.builtin.lineinfile:
path: /etc/rc.local
regexp:
"^.* mail -s (?!.*of.*).+$"
state: absent
tags:
- alerting
- name: "Set root mail alias"
ansible.builtin.replace:
dest: /etc/mail/aliases
regexp: "# root:"
replace: "root: {{ general_alert_email }}"
backup: false
notify:
- newaliases
tags:
- mail