Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
E-VANCE committed Oct 10, 2024
1 parent 874a3ef commit e63924b
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 0 deletions.
13 changes: 13 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
addons_dir: "{{ project_root }}/addons"
matomo_url: "https://builds.matomo.org/matomo-latest.zip"
matomo_php_extensions:
- php{{ php_version }}-gd
- php{{ php_version }}-curl
- php{{ php_version }}-zip
- php{{ php_version }}-mbstring
- php{{ php_version }}-xml
- php{{ php_version }}-cli
- php{{ php_version }}-mysql
matomo_owner: "{{ web_user }}"
matomo_group: "{{ web_group }}"
10 changes: 10 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- name: restart php{{ php_version }}-fpm
service:
name: php{{ php_version }}-fpm
state: restarted

- name: reload nginx
service:
name: nginx
state: reloaded
15 changes: 15 additions & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
galaxy_info:
author: Henning Orth / E-VANCE
description: Use Matomo with Trellis
license: MIT
min_ansible_version: 2.4
galaxy_tags:
- trellis
- wordpress
- networking
- system
- matomo
- piwik
- analytics
dependencies: []
90 changes: 90 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
- name: Install required PHP extensions for Matomo
apt:
name: "{{ item }}"
state: present
with_items: "{{ matomo_php_extensions }}"
notify: restart php{{ php_version }}-fpm

- name: Create addons folder for Matomo installation
file:
path: "{{ addons_dir }}"
owner: "{{ web_user }}"
group: "{{ web_group }}"
mode: '0755'
state: directory

- name: Download Matomo
get_url:
url: "{{ matomo_url }}"
dest: "/tmp/matomo_latest.zip"

- name: Unzip Matomo
unarchive:
src: "/tmp/matomo_latest.zip"
dest: "{{ addons_dir }}"
remote_src: yes
creates: "{{ addons_dir }}/matomo"

- name: Set ownership of Matomo files
file:
path: "{{ addons_dir }}/matomo"
owner: "{{ matomo_owner }}"
group: "{{ matomo_group }}"
recurse: yes

- name: Ensure correct permissions on Matomo directory
file:
path: "{{ addons_dir }}/matomo"
mode: '0755'
recurse: yes

- name: Create Matomo database
mysql_db:
name: "{{ matomo_db_name }}"
state: present
login_host: "{{ site_env.db_host }}"
login_user: "{{ mysql_root_user }}"
login_password: "{{ mysql_root_password }}"
with_dict: "{{ wordpress_sites }}"
tags: matomo

- name: Create Matomo database user and grant permissions
mysql_user:
name: "{{ item.value.matomo.db.user }}"
password: "{{ item.value.matomo.db.password }}"
host: "{{ site_env.db_user_host }}"
append_privs: yes
priv: "{{ matomo_db_name }}.*:ALL"
state: present
login_host: "{{ site_env.db_host }}"
login_user: "{{ mysql_root_user }}"
login_password: "{{ mysql_root_password }}"
with_dict: "{{ wordpress_sites }}"
tags: matomo

- name: Create symlink to Matomo
file:
path: "{{ deploy_helper.new_release_path }}/web/analytics"
src: "{{ addons_dir }}/matomo"
state: link
with_dict: "{{ wordpress_sites }}"
tags: matomo

- name: Explain next steps
debug:
msg: |
If necessary, set up Matomo as follows:
1) Deploy
2) Point your browser to {{ wordpress_env_defaults.wp_home }}/analytics
3) Proceed with the form using following credentials:
Host: {{ site_env.db_user_host }}
Database User: {{ item.value.matomo.db.user }}
Database Password: {{ item.value.matomo.db.password }}
Database: {{ matomo_db_name }}
Table Prefix: none
Set up your admin user.
4) Log in to Matomo.
5) Under Administration/System/Geolocation, download and activate the GeoIP 2 database.
with_dict: "{{ wordpress_sites }}"
tags: matomo
13 changes: 13 additions & 0 deletions tasks/nginx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
- name: Configure Nginx for Matomo
template:
src: "nginx-matomo.conf.j2"
dest: "/etc/nginx/sites-available/{{ site_host }}-matomo.conf"
notify: reload nginx

- name: Enable Nginx site for Matomo
file:
src: "/etc/nginx/sites-available/{{ site_host }}-matomo.conf"
dest: "/etc/nginx/sites-enabled/{{ site_host }}-matomo.conf"
state: link
notify: reload nginx
31 changes: 31 additions & 0 deletions templates/nginx-matomo.conf.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
server {
listen 80;
server_name {{ site_host }};
root {{ addons_dir }}/matomo;

index index.php index.html index.htm;

access_log /srv/www/{{ site_host }}/logs/matomo-access.log;
error_log /srv/www/{{ site_host }}/logs/matomo-error.log;

location / {
try_files $uri $uri/ =404;
}

location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php/php{{ php_version }}-fpm.sock;
}

location ~* \.(?:css|js|ico|gif|jpe?g|png)$ {
expires max;
add_header Cache-Control "public";
}

location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
}

0 comments on commit e63924b

Please sign in to comment.