Ansible playbook for host rebooted and started unexpectedly and send an alert

Hi All,

I am looking for ansible play book example to send alert to premetheus after a host has rebooted and re-started unexpeditly. Any help would be greatly appreciate it.

Thanks
Riaz

Not sure that is really an ansible task. I’m sure you could use ansible to set it up. I use this on my systems to get notification:
`

cd /etc/systemd/system
if [[ ! rebootsh.service ]]; then
cat > rebootsh.service << EOF
[Unit]
Description=Notify sys admin when the server gets rebooted
After=network.target
After=postfix.service

[Service]
Type=simple
ExecStart=/root/bin/reboot.sh
TimeoutStartSec=0
RemainAfterExit=no

[Install]
WantedBy=rescue.target
WantedBy=multi-user.target
WantedBy=graphical.target
EOF
echo “Added the rebootsh service”
chmod 444 rebootsh.service
systemctl enable rebootsh.service
else
echo “Rebootsh.service already in place”
fi

cd /root/bin
if [[ ! -f reboot.sh ]]; then
cat > reboot.sh << EOF
#!/bin/bash