I'm self-hosting my blog now and, with the move from Gatsby to Ghost, I also took advantage to move from Google analytics to Plausible. I aldready built a docker-based Plausible role built in Ansible inline (aka the same place where I have my playbooks). It translated the docker-compose conviguration to a bunch of docker_container tasks and was quite verbose.

Now I've created a separate role which is based on the docker_compose role, making things much easier. It:

  • Has a (minimal?) number of variables, with decent defaults,
  • Defines configuration files for the various components and
  • Only updates the docker_compose.yml file with the various variables.

Use the role

The role is designed to be easy to use and allow for backups (no backups == bad, from my own experience). You only need to define some variables:

# host_vars/my_host.yml

plausible_port: "20100"
plausible_base_url: "https://metrics.lipc.tech"
plausible_volume_geoip: "/mnt/geoip"
plausible_admin_user_email: "[email protected]"
plausible_admin_user_name: "admin"
plausible_db_port: "20101"

Then, you can call the role in your playbook:

- name: Deploy services
  hosts: myhost
  roles:
    - 'laurivan.plausible'

If you look at the defaults, you will see all possible configurations. You can dive in the templates as well to see e.g. how the docker-compose.yml file is built (and you can also suggest improvements!).

Roadmap

This role satisfies my needs right now, but I'm open to suggestions :)

Bonus

As mentioned above, the PostgreSQL post can be made public, so other components have access to it, e.g., for backup. If you're using ansible-role-backup, you can easily add it to the configuration:

borg_repository: "/mnt/backup/services"
borg_source_directories:
  # Plausible
  - /mnt/plausible/config
borg_exclude_patterns:
  - 'logs/*.log*'
borg_retention_policy:
  keep_hourly: 3
  keep_daily: 7
  keep_weekly: 4
  keep_monthly: 6
borgmatic_hooks:
  postgresql_databases:
    - name: plausible_db
      hostname: <IP of host>
      port: "{{ plausible_db_port }}"
      username: postgres
      password: "{{ plausible_db_password }}"

Conclusion

I encourage you to read the documentation as it is the de-facto reference for this role and is up to date.

HTH,