Plausible analytics Ansible role https://plausible.io/
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-11-06 00:20:10 +00:00
.forgejo/workflows fix: moved to new pipeline 2026-10-12 16:35:19 +07:00
defaults feat: added nightly database dumps 2026-11-06 01:20:00 +01:00
files feat: added nightly database dumps 2026-11-06 01:20:00 +01:00
meta breaking: bumped versions, changed datapath 2026-11-06 01:04:35 +01:00
tasks feat: added nightly database dumps 2026-11-06 01:20:00 +01:00
templates feat: added nightly database dumps 2026-11-06 01:20:00 +01:00
.gitignore feat: basic plausible version 2026-04-27 22:49:10 +02:00
CHANGELOG.md feat: added nightly database dumps 2026-11-06 01:20:00 +01:00
LICENSE feat: basic plausible version 2026-04-27 22:49:10 +02:00
README.md Prettified Code! 2026-11-06 00:20:10 +00:00

Plausible

Deploys a Plausible Community Edition instance via Docker Compose with PostgreSQL and ClickHouse, routed through Traefik as a reverse proxy.

Requirements

  • Docker
  • community.docker Ansible collection

Variables

Variable Default Description
plausible_instance plausible Unique instance name. Used as Compose project name and container name prefix. Change when running multiple instances on the same host.
plausible_version v3.2.1 Plausible CE image tag. Pin to a specific version in production.
plausible_pg_version 18-alpine PostgreSQL image tag.
plausible_clickhouse_version 25.11-alpine ClickHouse image tag.
plausible_data_path /data/plausible Host path for persistent data (database, event data, uploads).
plausible_docker_path /docker/plausible Host path for the compose.yml file and ClickHouse config files.
plausible_domain ~ Public domain Plausible runs on (no protocol prefix). Required.
plausible_port ~ When set, exposes Plausible on this host port. Omit when using a reverse proxy.
plausible_traefik true When true, attaches to the traefik_web network and adds Traefik routing labels.
plausible_secret_key ~ Secret key for cryptographic signing. Required. See Secret Generation.
plausible_totp_key ~ TOTP vault encryption key. Required. See Secret Generation.
plausible_db_password ~ PostgreSQL user password. Required. Generate with openssl rand -hex 32.
plausible_email_verification false When true, requires email verification for new accounts.
plausible_disable_registration invite_only Controls who can register. Accepted values: true (nobody), false (everyone), invite_only.
plausible_mail_conf ~ SMTP mail configuration dict. See Mail.
plausible_backup_cron ~ Cron schedule for nightly dumps of both databases into <plausible_data_path>/backup. ~ disables it. See Backup.
plausible_uninstall false Stops and removes containers and the compose directory.
plausible_purge false Also removes the data directory. Requires plausible_uninstall: true. Irreversible.

Secret Generation

All three secrets must be generated before the first deploy:

openssl rand -base64 48  # → plausible_secret_key
openssl rand -base64 32  # → plausible_totp_key
openssl rand -hex 32     # → plausible_db_password

Copy the output values into your inventory:

plausible_secret_key: "..."
plausible_totp_key: "..."
plausible_db_password: "..."

Usage

Minimal setup:

plausible_domain: "analytics.example.com"
plausible_db_password: "{{ vault_plausible_db_password }}"
plausible_secret_key: "{{ vault_plausible_secret_key }}"
plausible_totp_key: "{{ vault_plausible_totp_key }}"

With mail and open registration:

plausible_domain: "analytics.example.com"
plausible_db_password: "{{ vault_plausible_db_password }}"
plausible_secret_key: "{{ vault_plausible_secret_key }}"
plausible_totp_key: "{{ vault_plausible_totp_key }}"
plausible_disable_registration: "false"
plausible_email_verification: true
plausible_mail_conf:
  host: smtp.example.com
  username: plausible@example.com
  password: "{{ vault_plausible_smtp_password }}"

Multiple instances on the same host:

# instance 1
plausible_instance: plausible_team_a
plausible_domain: analytics-a.example.com
plausible_data_path: /data/plausible_team_a
plausible_docker_path: /docker/plausible_team_a
plausible_db_password: "secret_a"
# ... other secrets

# instance 2
plausible_instance: plausible_team_b
plausible_domain: analytics-b.example.com
plausible_data_path: /data/plausible_team_b
plausible_docker_path: /docker/plausible_team_b
plausible_db_password: "secret_b"
# ... other secrets

Mail

plausible_mail_conf is a dict. When unset, Plausible cannot send emails (invites, reports, password resets).

Key Required Default Description
host yes — SMTP server hostname.
username yes — SMTP username.
password yes — SMTP password.
port no 465 SMTP port.
ssl no true true for TLS, false to disable.
address no username From address. Defaults to username.

Backup

Copying the live database directories does not give a consistent backup. With plausible_backup_cron set (e.g. "30 2 * * *"), the role installs /usr/local/bin/<plausible_instance>-backup and a cron job that writes:

  • backup/postgres/plausible_db.dump: pg_dump -Fc of users, sites and settings;
  • backup/clickhouse/latest/: a native ClickHouse BACKUP of plausible_events_db (events, sessions, imports), schema included.

Each run writes beside the last good copy first, so a failed run never replaces it. Point a file-level backup (restic etc.) at <plausible_data_path>/backup and schedule it after the dump.

Restore into a fresh deploy (same secrets, empty plausible_data_path), with the backup copied back to <plausible_data_path>/backup:

docker stop plausible-app
docker exec -i plausible-db pg_restore -U postgres -d plausible_db --clean --if-exists \
  < /data/plausible/backup/postgres/plausible_db.dump
docker exec plausible-events-db clickhouse-client --query "DROP DATABASE plausible_events_db SYNC"
docker exec plausible-events-db clickhouse-client \
  --query "RESTORE DATABASE plausible_events_db FROM File('latest')"
docker start plausible-app

Uninstall

To stop and remove all containers and the compose directory:

plausible_uninstall: true

To also wipe all data including the database and event data (irreversible):

plausible_uninstall: true
plausible_purge: true

Notes

  • plausible_domain is always required — it is used in BASE_URL regardless of the plausible_traefik setting.
  • plausible_data_path/db is owned by 70:70 (PostgreSQL Alpine container user), mode 0700.
  • plausible_data_path/data is owned by 999:65533 (Plausible app container user).
  • ClickHouse data and log directories are created as root; the ClickHouse container entrypoint chowns them to 101:101 at startup.
  • All secret variables (plausible_db_password, plausible_secret_key, plausible_totp_key) should be stored in Ansible Vault.
  • The role ships four static ClickHouse config files that reduce memory and CPU usage, suitable for small self-hosted setups.