OPNsense Dashboard

This role configures the OPNsense web UI dashboard widget layout via the REST API. It applies a defined widget layout including widget positions, sizes, and per-widget configurations (e.g.

Ansible Bash DHCP DNS HTTPS JSON OPNsense REST API

OPNsense Dashboard Role

Overview

This role configures the OPNsense web UI dashboard widget layout via the REST API. It applies a defined widget layout including widget positions, sizes, and per-widget configurations (e.g., selected interfaces for traffic graph, thermal sensor selection). The layout is always applied to ensure consistency.

Purpose

  • Dashboard as Code: Define dashboard layout in version-controlled configuration
  • Consistency: Ensure the same dashboard layout after OPNsense upgrades or accidental changes
  • Per-User: Dashboard is saved for the API user account
  • API-Based: Reliable automation via OPNsense REST API

Requirements

  • Ansible 2.9 or higher
  • OPNsense firewall with API access enabled
  • API key and secret stored in Ansible Vault
  • Network connectivity to OPNsense (VLAN10)

Role Variables

Required Variables

VariableRequiredDescription
vault_opnsense_bjoffrey_user_api_keyYesOPNsense API key (in vault)
vault_opnsense_bjoffrey_user_api_secretYesOPNsense API secret (in vault)
opnsense_dashboard_widgetsYesList of widget definitions (in vars file)

Optional Variables

VariableDefaultDescription
opnsense_dashboard_validate_certstrueValidate SSL certificates
opnsense_dashboard_options{}Dashboard-level options

Widget Definition

Each widget in opnsense_dashboard_widgets has:

FieldTypeDescription
idstringWidget identifier (e.g., cpu, memory, traffic)
xintHorizontal grid position (0-11)
yintVertical position in pixels
wint/nullWidth in grid columns (null = default)
hintHeight in pixels
minWintMinimum width in grid columns
widgetdictWidget-specific configuration
sizeToContentintOptional, auto-size height

Widget Configuration Examples

Traffic Graph with Selected Interfaces

- id: "traffic"
  x: 8
  y: 0
  w: 4
  h: 446
  minW: 2
  widget:
    interfaces:
      - "opt3"
      - "wan"

CPU with Total Graph

- id: "cpu"
  x: 2
  y: 0
  w: 2
  h: 177
  minW: 2
  widget:
    graphs:
      - "total"

Thermal Sensors with Selected Sensors

- id: "thermalsensors"
  x: 2
  y: 177
  w: 2
  h: 180
  minW: 2
  widget:
    sensors:
      - "dev.cpu.0.temperature"
      - "hw.acpi.thermal.tz0.temperature"

Simple Widget (No Configuration)

- id: "memory"
  x: 2
  y: 528
  w: null
  h: 143
  minW: 1
  widget: {}

Available Widgets

Widget IDDescription
announcementsOPNsense announcements feed
certificatesCertificate status and expiry
carpCARP/VRRP status
cpuCPU usage graph
diskDisk usage gauge
dmidecodeDMI/hardware information
dnsmasqleasesDnsmasq DHCP leases
firewallFirewall live log
firewallstatesFirewall state table usage
gatewaysGateway status and RTT
interfacestatisticsInterface byte/packet counters
interfacesInterface overview
ipsecleasesIPsec VPN leases
ipsectunnelsIPsec tunnel status
livelogSystem live log
mbufNetwork buffer usage
memoryMemory usage gauge
monitMonit service status
openvpnclientsOpenVPN client connections
openvpnserversOpenVPN server connections
pictureSystem picture
servicesService status list
smartSMART disk health
swapSwap usage gauge
systeminformationSystem info (hostname, uptime, etc.)
thermalsensorsCPU/system temperature
trafficTraffic graph
WireguardWireGuard tunnel status

Dependencies

This role has no dependencies on other Ansible roles.

Example Playbook

---
- name: Configure OPNsense Dashboard
  hosts: mint-vm
  gather_facts: false

  vars_files:
    - ../../roles/opnsense_dashboard/vars/widgets.yml

  tasks:
    - name: Configure dashboard widget layout
      ansible.builtin.include_role:
        name: opnsense_dashboard

What This Role Does

  1. POST widget layout to /api/core/dashboard/save_widgets
    • Sends the full widget list with positions, sizes, and configurations
    • API returns {"result": "saved"}

The role always applies the desired layout. This is a lightweight API call that ensures the dashboard matches the defined configuration.

OPNsense API Endpoints

Get Dashboard

GET /api/core/dashboard/get_dashboard
Authorization: Basic (API key:secret)

Returns available modules and current widget layout.

Save Widgets

POST /api/core/dashboard/save_widgets
Authorization: Basic (API key:secret)
Content-Type: application/json

Request body:

{
  "options": {},
  "widgets": [
    {
      "id": "cpu",
      "x": 0,
      "y": 0,
      "w": 2,
      "h": 177,
      "minW": 2,
      "widget": {
        "graphs": ["total"]
      }
    }
  ]
}

Response:

{
  "result": "saved"
}

Restore Defaults

POST /api/core/dashboard/restore_defaults
Authorization: Basic (API key:secret)

Resets dashboard to factory default layout.

Per-User Dashboard

The dashboard layout is stored per API user. If you log into the web UI with a different account (e.g., root) than the API key user, you will not see the changes. Ensure the API key belongs to the same user whose dashboard you want to configure.

Grid System

The dashboard uses a 12-column grid:

|  0  |  1  |  2  |  3  |  4  |  5  |  6  |  7  |  8  |  9  | 10  | 11  |
  • x: Starting column (0-11)
  • w: Number of columns to span (1-12, or null for default)
  • y: Vertical position in pixels (widgets stack vertically)
  • h: Height in pixels

Security Considerations

  • API Credentials: Stored in Ansible Vault
  • HTTPS: Uses SSL/TLS for API calls
  • Basic Auth: API key/secret authentication
  • Certificate Validation: Enabled by default
  • No sensitive data: Dashboard layout contains no secrets

Troubleshooting

Dashboard not updating in web UI

Cause: API user differs from web UI login user

Solution: Log into the web UI with the same account that owns the API key.

Widget placement incorrect

Cause: Wrong x/y/w/h values in widget definition

Solution: Use the web UI to arrange widgets, then capture the layout via GET request:

curl -u "key:secret" \
  https://opnsense-ip/api/core/dashboard/get_dashboard | jq '.dashboard.widgets'

Update the vars file with the correct values.

This role is often used with:

  • opnsense_conf_backup: Backup OPNsense configuration
  • opnsense_firewall: Configure firewall rules
  • opnsense_trust_certificates: Manage SSL/TLS certificates

License

MIT

Author

Created for homelab infrastructure management.