Compare commits

...

10 Commits

Author SHA1 Message Date
106116b497 Lint 2022-09-30 07:57:17 +02:00
86fca6c87d Merge branch 'master' of https://git.home.lipc.tech/Dev/ansible-role-plausible 2022-09-26 12:19:33 +02:00
9e3e63e7c6 Typo. 2022-09-26 12:19:32 +02:00
570e15ed05 Typo
Signed-off-by: laur <laur.ivan@gmail.com>
2022-09-23 18:34:05 +00:00
ec75520bd4 Add documentation.
Better configuration.
Expose DB port.
2022-09-23 12:50:15 +02:00
a0a0755bb4 Typo 2022-09-22 12:50:10 +02:00
8134080cf8 Use the uid and gid of the user.
Default email address for admin.
2022-09-22 12:41:15 +02:00
8a3adb0ce2 Create directories via become. 2022-09-22 11:41:17 +02:00
d970ae0683 Specify geoip file. 2022-09-22 11:34:33 +02:00
5829f66490 Specific image name for testing. 2022-09-22 11:22:20 +02:00
11 changed files with 164 additions and 45 deletions

137
README.md
View File

@ -1,38 +1,127 @@
Role Name
=========
# laurivan.plausible
A brief description of the role goes here.
This is a role to install [Plausible](https://plausible.io/) via Docker.
Requirements
------------
## Requirements
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.
You need a machine with Docker installed.
Role Variables
--------------
## Role Variables
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 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`).
Dependencies
------------
# Plausible parameters
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.
`plausible_port` defined the exposed port for the web site (including JS delivery and API):
Example Playbook
----------------
```yaml
plausible_port: 8000
```
You need an admin user to be able to access the site:
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
```yaml
plausible_admin_user_email: changeme@example.com
plausible_admin_user_name: change-me
plausible_admin_user_pwd: change-me
```
- hosts: servers
roles:
- { role: username.rolename, x: 42 }
The hosting URL of the server, used for URL generation must be specified:
License
-------
```yaml
plausible_base_url: change-me
```
BSD
Please define a long (>= 64 characters) secret key, which will be used by your instance to encrypt data:
Author Information
------------------
```yaml
plausible_secret_key_base: change-me
```
An optional section for the role authors to include contact information, or a website (HTML is not allowed).
# 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).

3
TODO.md Normal file
View File

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

View File

@ -1,6 +1,9 @@
---
# defaults file for plausible
# Plausible
plausible_version: "latest"
# Email
plausible_smtp_host:
plausible_smtp_port: 587
@ -9,7 +12,7 @@ plausible_smtp_password:
# Plausible parameters
plausible_port: 8000
plausible_admin_user_email: change-me
plausible_admin_user_email: changeme@example.com
plausible_admin_user_name: change-me
plausible_admin_user_pwd: change-me
plausible_base_url: change-me
@ -19,9 +22,13 @@ 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"
@ -29,3 +36,6 @@ 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,4 +9,3 @@
roles:
- role: laurivan.plausible

View File

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

View File

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

View File

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

View File

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

4
templates/env.db.conf.j2 Normal file
View File

@ -0,0 +1,4 @@
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_geoip_stat.stat.exists %}
GEOLITE2_COUNTRY_DB={{ plausible_volume_geoip }}/GeoLite2-Country.mmdb
{% if plausible_volume_geoip and plausible_geoip_db and plausible_geoip_stat.stat.exists %}
GEOLITE2_COUNTRY_DB={{ plausible_volume_geoip }}/{{ plausible_geoip_db }}
{% endif %}
# DB and events
DATABASE_URL=postgres://postgres:{{ plausible_pg_password }}@plausible_db:5432/plausible_db
DATABASE_URL=postgres://postgres:{{ plausible_db_password }}@{{ plausible_db_host }}:5432/{{ plausible_db }}
CLICKHOUSE_DATABASE_URL=http://plausible_events_db:8123/plausible_events_db
#SMTP