--- - name: Fetch rc.local content command: "grep -v '^#' /etc/rc.local" check_mode: false register: rclocal_content failed_when: false changed_when: false tags: - misc - name: Configure rc.local 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: - misc - name: Delete rc.local entry of boot/reboot not precising hostname lineinfile: path: /etc/rc.local regexp: "^.* mail -s (?!.*of.*).+$" state: absent tags: - misc - name: Set root mail alias replace: dest: /etc/mail/aliases regexp: "# root:" replace: "root: {{ general_alert_email }}" backup: false notify: - newaliases tags: - mail