Compare commits

..

No commits in common. "master" and "1.0.0" have entirely different histories.

11 changed files with 45 additions and 164 deletions

137
README.md
View File

@ -1,127 +1,38 @@
# laurivan.plausible
Role Name
=========
This is a role to install [Plausible](https://plausible.io/) via Docker.
A brief description of the role goes here.
## Requirements
Requirements
------------
You need a machine with Docker installed.
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
## Role Variables
Role Variables
--------------
Plausible depends on several components (SMTP, Clickhouse, PostgreSQL) and this role is designed to install them as a package. All variables are listed below (see also `defaults/main.yml`).
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
# Plausible parameters
Dependencies
------------
`plausible_port` defined the exposed port for the web site (including JS delivery and API):
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
```yaml
plausible_port: 8000
```
You need an admin user to be able to access the site:
Example Playbook
----------------
```yaml
plausible_admin_user_email: changeme@example.com
plausible_admin_user_name: change-me
plausible_admin_user_pwd: change-me
```
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
The hosting URL of the server, used for URL generation must be specified:
- hosts: servers
roles:
- { role: username.rolename, x: 42 }
```yaml
plausible_base_url: change-me
```
License
-------
Please define a long (>= 64 characters) secret key, which will be used by your instance to encrypt data:
BSD
```yaml
plausible_secret_key_base: change-me
```
Author Information
------------------
# Email
Plausible can send various emails; for this it needs a SMTP relay. Following variables define the SMTP account from which emails will be sent:
```yaml
plausible_smtp_host:
plausible_smtp_port: 587
plausible_smtp_username:
plausible_smtp_password:
```
If you don't define any, no emails will be sent and you'll need to look through the logs :)
The email on behalf of which messages are sent is defined by:
```yaml
plausible_smtp_email: "changeme@example.com"
```
## Database
Plausible depends on PostgreSQL and Clickhouse.
For PostgreSQL, you need to specify following variables:
```yaml
plausible_db_host: "plausible_db"
plausible_db: "plausible"
plausible_db_password: "change_me"
```
If you want to expose the database port outside (e.g. for backup), please define `plausible_db_port`
For Clickhouse, you only need to define the version used:
```yaml
plausible_clickhouse_version: "21.3.2.5"
```
### Volumes
The role will create following paths used by the docker containers as volumes:
```yaml
plausible_volume_base: "/mnt/plausible"
plausible_volume_config: "{{ plausible_volume_base }}/config"
plausible_volume_db: "{{ plausible_volume_base }}/db_data"
plausible_volume_events: "{{ plausible_volume_base }}/event_data"
plausible_volume_geoip: "{{ plausible_volume_base }}/geoip_data"
```
The `plausible_volume_geoip` is necessary to access MaxMind GeoIP data (see below).
### GeoIP
Plausible defaults to DBIP, but can be configured to use MaxMind GeoIP. If you want to use MaxMind, you need to define:
```yaml
plausible_geoip_db: "GeoLite2-Country.mmdb"
```
## Dependencies
None
## Example Playbook
```yaml
---
- name: Example playbook
hosts: services
vars:
plausible_port: "8100"
plausible_base_url: "https://metrics.example.com"
plausible_admin_user_email: "admin@example.com"
plausible_admin_user_name: "admin"
plausible_admin_user_pwd: "change-me"
roles:
- 'laurivan.plausible'
```
## License
MIT
## Author Information
This role was created in 2022 by [Laur Ivan](https://www.laurivan.com).
An optional section for the role authors to include contact information, or a website (HTML is not allowed).

View File

@ -1,3 +0,0 @@
# Roadmap
- [ ] Allow external postgres instance

View File

@ -1,9 +1,6 @@
---
# defaults file for plausible
# Plausible
plausible_version: "latest"
# Email
plausible_smtp_host:
plausible_smtp_port: 587
@ -12,7 +9,7 @@ plausible_smtp_password:
# Plausible parameters
plausible_port: 8000
plausible_admin_user_email: changeme@example.com
plausible_admin_user_email: change-me
plausible_admin_user_name: change-me
plausible_admin_user_pwd: change-me
plausible_base_url: change-me
@ -22,13 +19,9 @@ plausible_secret_key_base: change-me
plausible_smtp_email: "changeme@example.com"
# Database
plausible_db_port:
plausible_db_host: "plausible_db"
plausible_db: "plausible_db"
plausible_db_password: "change_me"
plausible_clickhouse_version: "21.3.2.5"
plausible_version: "latest"
plausible_pg_password: "change_me"
# Volumes
plausible_volume_base: "/mnt/plausible"
@ -36,6 +29,3 @@ plausible_volume_config: "{{ plausible_volume_base }}/config"
plausible_volume_db: "{{ plausible_volume_base }}/db_data"
plausible_volume_events: "{{ plausible_volume_base }}/event_data"
plausible_volume_geoip: "{{ plausible_volume_base }}/geoip_data"
# GeoIP
plausible_geoip_db: "GeoLite2-Country.mmdb"

View File

@ -9,3 +9,4 @@
roles:
- role: laurivan.plausible

View File

@ -8,7 +8,7 @@
# Developer must implement.
- name: Remove the docker image
community.docker.docker_container:
name: instance-plausible
name: instance
state: absent
# Mandatory configuration for Molecule to function.

View File

@ -10,7 +10,7 @@ dependency:
driver:
name: docker
platforms:
- name: instance-plausible
- name: instance
image: "geerlingguy/docker-${MOLECULE_DISTRO:-centos8}-ansible:latest"
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:

View File

@ -1,24 +1,15 @@
---
- name: Setup the test machine
hosts: instance-plausible
hosts: instance
tasks:
- name: Check if /var/run/docker.sock already exists
ansible.builtin.stat:
path: "/var/run/docker.sock"
register: docker_sock_stat
- name: Create docker.sock
raw: touch /var/run/docker.sock
become: true
changed_when: false
when: not docker_sock_stat.stat.exists
- name: Move docker.sock from tmp
raw: mount --move /tmp/docker_mounted.sock /var/run/docker.sock
become: true
changed_when: false
when: not docker_sock_stat.stat.exists
- name: Update apt cache.
apt: update_cache=yes cache_valid_time=600
when: ansible_os_family == 'Debian'

View File

@ -1,31 +1,30 @@
---
# tasks file for plausible
# Check if geoip volume exists
- name: Check if geoip volume exists
ansible.builtin.stat:
path: "{{ plausible_volume_geoip }}/{{ plausible_geoip_db }}"
path: "{{ plausible_volume_geoip }}/GeoLite2-Country.mmdb"
register: plausible_geoip_stat
- name: Set up directories
ansible.builtin.file:
state: directory
path: "{{ item }}"
owner: "{{ ansible_effective_user_id }}"
group: "{{ ansible_effective_group_id }}"
mode: "0750"
mode: 0755
with_items:
- "{{ plausible_volume_config }}"
- "{{ plausible_volume_events }}"
- "~/plausible"
tags:
- configuration
become: true
become: false
- name: Set up the database directory.
ansible.builtin.file:
state: directory
path: "{{ item }}"
mode: "0755"
mode: 0755
owner: 70
with_items:
- "{{ plausible_volume_db }}"
@ -41,7 +40,6 @@
loop:
- "env.plausible.conf"
- "env.mail.conf"
- "env.db.conf"
tags:
- configuration
@ -49,7 +47,7 @@
ansible.builtin.copy:
src: "{{ item }}"
dest: "{{ plausible_volume_config }}/{{ item }}"
mode: '0644'
mode: '0640'
loop:
- "clickhouse-config.xml"
- "clickhouse-user-config.xml"
@ -69,3 +67,4 @@
project_src: ~/plausible/
build: false
become: false

View File

@ -13,12 +13,8 @@ services:
restart: always
volumes:
- {{ plausible_volume_db }}:/var/lib/postgresql/data
{% if plausible_db_port %}
ports:
- {{ plausible_db_port }}:5432
{% endif %}
env_file:
- {{ plausible_volume_config }}/env.db.conf
environment:
- POSTGRES_PASSWORD={{ plausible_pg_password }}
networks:
- plausible
@ -48,9 +44,9 @@ services:
- {{ plausible_port }}:8000
env_file:
- {{ plausible_volume_config }}/env.plausible.conf
{% if plausible_volume_geoip and plausible_geoip_db and plausible_geoip_stat.stat.exists %}
{% if plausible_geoip_stat.stat.exists %}
volumes:
- {{ plausible_volume_geoip }}/{{ plausible_geoip_db }}:/geoip:ro
- {{ plausible_volume_geoip }}/GeoLite2-Country.mmdb:/geoip:ro
{% else %}
# No GeoIP data volume
{% endif%}

View File

@ -1,4 +0,0 @@
POSTGRES_USER=postgres
POSTGRES_PASSWORD={{ plausible_db_password }}
POSTGRES_DB={{ plausible_db }}

View File

@ -4,12 +4,12 @@ ADMIN_USER_PWD={{ plausible_admin_user_pwd }}
BASE_URL={{ plausible_base_url }}
SECRET_KEY_BASE={{ plausible_secret_key_base }}
{% if plausible_volume_geoip and plausible_geoip_db and plausible_geoip_stat.stat.exists %}
GEOLITE2_COUNTRY_DB={{ plausible_volume_geoip }}/{{ plausible_geoip_db }}
{% if plausible_geoip_stat.stat.exists %}
GEOLITE2_COUNTRY_DB={{ plausible_volume_geoip }}/GeoLite2-Country.mmdb
{% endif %}
# DB and events
DATABASE_URL=postgres://postgres:{{ plausible_db_password }}@{{ plausible_db_host }}:5432/{{ plausible_db }}
DATABASE_URL=postgres://postgres:{{ plausible_pg_password }}@plausible_db:5432/plausible_db
CLICKHOUSE_DATABASE_URL=http://plausible_events_db:8123/plausible_events_db
#SMTP