Fix files and templates.

Check if the GeoIP db exists and configure accordingly.
Move preparation tasks to prepare.yml.
Fix destroy.yml.
This commit is contained in:
Laur Ivan 2022-09-22 09:43:03 +02:00
parent 7c674a8891
commit 347f54fd79
11 changed files with 95 additions and 41 deletions

View File

@ -24,8 +24,8 @@ plausible_version: "latest"
plausible_pg_password: "change_me"
# Volumes
plausible_base: "/mnt/plausible"
plausible_config: "{{ plausible_base }}/config"
plausible_db_data: "{{ plausible_base }}/db_data"
plausible_event_data: "{{ plausible_base }}/event_data"
plausible_geoip_database: "{{ plausible_base }}/geoip_data"
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"

View File

@ -1,2 +1,8 @@
---
# handlers file for plausible
- name: Restart plausible
community.docker.docker_compose:
project_src: ~/plausible/
build: false
restarted: true
become: false

View File

@ -3,20 +3,9 @@
hosts: all
# gather_facts: false
pre_tasks:
- name: Update apt cache.
apt: update_cache=yes cache_valid_time=600
when: ansible_os_family == 'Debian'
- name: Install python requests
pip:
name:
- requests
- docker
- docker-compose
- name: Install docker
vars:
docker_service_manage: false
include_role:
name: geerlingguy.docker
- name: "Include necessary variables"
ansible.builtin.include_vars:
file: "../../.env.yml"
roles:
- role: laurivan.plausible

View File

@ -6,6 +6,10 @@
no_log: "{{ molecule_no_log }}"
tasks:
# Developer must implement.
- name: Remove the docker image
community.docker.docker_container:
name: instance
state: absent
# Mandatory configuration for Molecule to function.

View File

@ -10,3 +10,17 @@
raw: mount --move /tmp/docker_mounted.sock /var/run/docker.sock
become: true
changed_when: false
- name: Update apt cache.
apt: update_cache=yes cache_valid_time=600
when: ansible_os_family == 'Debian'
- name: Install python requests
pip:
name:
- requests
- docker
- docker-compose
- name: Install docker
vars:
docker_service_manage: false
include_role:
name: geerlingguy.docker

View File

@ -1,18 +1,20 @@
---
# 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"
register: plausible_geoip_stat
- name: Set up directories
ansible.builtin.file:
state: directory
path: "{{ item }}"
mode: 0755
with_items:
- "{{ plausible_volume_media }}"
- "{{ plausible_volume_certs }}"
- "{{ plausible_volume_geoip }}"
- "{{ plausible_volume_templates }}"
- "{{ plausible_volume_config }}"
- "{{ plausible_volume_redis }}"
- "{{ plausible_volume_events }}"
- "~/plausible"
tags:
- configuration
@ -28,7 +30,29 @@
- "{{ plausible_volume_db }}"
tags:
- configuration
become: false
become: true
- name: Write plausible configuration (1)
ansible.builtin.template:
src: "{{ item }}.j2"
dest: "{{ plausible_volume_config }}/{{ item }}"
mode: '0640'
loop:
- "env.plausible.conf"
- "env.mail.conf"
tags:
- configuration
- name: Write plausible configuration (2)
ansible.builtin.copy:
src: "{{ item }}"
dest: "{{ plausible_volume_config }}/{{ item }}"
mode: '0640'
loop:
- "clickhouse-config.xml"
- "clickhouse-user-config.xml"
tags:
- configuration
- name: Copy plausible docker-compose template.
ansible.builtin.template:
@ -38,14 +62,6 @@
become: false
notify: Restart plausible
- name: Copy plausible configuration.
ansible.builtin.template:
src: templates/env.plausible.conf.j2
dest: "{{ plausible_volume_config }}/env.plausible.conf"
mode: '0640'
become: false
notify: Restart plausible
- name: Ensure plausible is running.
community.docker.docker_compose:
project_src: ~/plausible/

View File

@ -3,6 +3,8 @@ services:
mail:
image: bytemark/smtp
restart: always
env_file:
- {{ plausible_volume_config }}/env.mail.conf
networks:
- plausible
@ -10,9 +12,9 @@ services:
image: postgres:12
restart: always
volumes:
- {{ plausible_db_data }}:/var/lib/postgresql/data
- {{ plausible_volume_db }}:/var/lib/postgresql/data
environment:
- POSTGRES_PASSWORD=postgres
- POSTGRES_PASSWORD={{ plausible_pg_password }}
networks:
- plausible
@ -20,9 +22,9 @@ services:
image: clickhouse/clickhouse-server:22.6-alpine
restart: always
volumes:
- {{ plausible_event_data }}:/var/lib/clickhouse
- {{ plausible_config }}/clickhouse-config.xml:/etc/clickhouse-server/config.d/logging.xml:ro
- {{ plausible_config }}/clickhouse-user-config.xml:/etc/clickhouse-server/users.d/logging.xml:ro
- {{ plausible_volume_events }}:/var/lib/clickhouse
- {{ plausible_volume_config }}/clickhouse-config.xml:/etc/clickhouse-server/config.d/logging.xml:ro
- {{ plausible_volume_config }}/clickhouse-user-config.xml:/etc/clickhouse-server/users.d/logging.xml:ro
ulimits:
nofile:
soft: 262144
@ -41,9 +43,13 @@ services:
ports:
- {{ plausible_port }}:8000
env_file:
- {{ plausible_config }}/env.plausible.conf
- {{ plausible_volume_config }}/env.plausible.conf
{% if plausible_geoip_stat.stat.exists %}
volumes:
- {{ plausible_geoip_database }}:/geoip:ro
- {{ plausible_volume_geoip }}/GeoLite2-Country.mmdb:/geoip:ro
{% else %}
# No GeoIP data volume
{% endif%}
networks:
- plausible

View File

@ -1,4 +1,6 @@
{%if plausible_smtp_host %}
RELAY_HOST={{ plausible_smtp_host }}
RELAY_PORT={{ plausible_smtp_port }}
RELAY_USERNAME={{ plausible_smtp_username }}
RELAY_PASSWORD={{ plausible_smtp_password }}
{% endif %}

View File

@ -0,0 +1,17 @@
ADMIN_USER_EMAIL={{ plausible_admin_user_email }}
ADMIN_USER_NAME={{ plausible_admin_user_name }}
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
{% endif %}
# DB and events
DATABASE_URL=postgres://postgres:{{ plausible_pg_password }}@plausible_db:5432/plausible_db
CLICKHOUSE_DATABASE_URL=http://plausible_events_db:8123/plausible_events_db
#SMTP
SMTP_HOST_ADDR=plausible_mail
MAILER_EMAIL={{ plausible_smtp_email }}