Setting up watchdog on Raspberry Pi with Ansible

Posted on 31 August 2021

The Raspberry Pi has a hardware watchdog timer on its board that is able to restart the board. This is a super useful feature if you want your Pi to restart in the case of a system failure like a kernel panic or a process consuming all resources. This page explains how to set this up manually on a Pi.

Here’s the equivalent ansible playbook:

---
- hosts: all
  become: yes
  tasks:

    - name: 'Enable watchdog in boot/config.txt'
      import_role:
        name: infothrill.rpi_boot_config
      vars:
        boot_config_lines:
          - "dtparam=watchdog=on"

    - name: 'Configure the watchdog'
      import_role:
        name: danmilon.watchdog
      vars:
        watchdog_device: /dev/watchdog
        watchdog_timeout: 15
        watchdog_realtime: yes
        watchdog_priority: 1
        watchdog_max_load_1: 24

To install dependancies:

ansible-galaxy install infothrill.rpi_boot_config
ansible-galaxy install danmilon.watchdog

The system should then restart automatically if you crash the system, e.g. by triggering a kernel panic:

# WARNING THIS WILL CRASH YOUR SYSTEM
echo c > /proc/sysrq-trigger

Some notes: