Skip to content

Commit e63924b

Browse files
committed
Initial commit
1 parent 874a3ef commit e63924b

File tree

6 files changed

+172
-0
lines changed

6 files changed

+172
-0
lines changed

defaults/main.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
addons_dir: "{{ project_root }}/addons"
3+
matomo_url: "https://builds.matomo.org/matomo-latest.zip"
4+
matomo_php_extensions:
5+
- php{{ php_version }}-gd
6+
- php{{ php_version }}-curl
7+
- php{{ php_version }}-zip
8+
- php{{ php_version }}-mbstring
9+
- php{{ php_version }}-xml
10+
- php{{ php_version }}-cli
11+
- php{{ php_version }}-mysql
12+
matomo_owner: "{{ web_user }}"
13+
matomo_group: "{{ web_group }}"

handlers/main.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
- name: restart php{{ php_version }}-fpm
3+
service:
4+
name: php{{ php_version }}-fpm
5+
state: restarted
6+
7+
- name: reload nginx
8+
service:
9+
name: nginx
10+
state: reloaded

meta/main.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
galaxy_info:
3+
author: Henning Orth / E-VANCE
4+
description: Use Matomo with Trellis
5+
license: MIT
6+
min_ansible_version: 2.4
7+
galaxy_tags:
8+
- trellis
9+
- wordpress
10+
- networking
11+
- system
12+
- matomo
13+
- piwik
14+
- analytics
15+
dependencies: []

tasks/main.yml

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
- name: Install required PHP extensions for Matomo
3+
apt:
4+
name: "{{ item }}"
5+
state: present
6+
with_items: "{{ matomo_php_extensions }}"
7+
notify: restart php{{ php_version }}-fpm
8+
9+
- name: Create addons folder for Matomo installation
10+
file:
11+
path: "{{ addons_dir }}"
12+
owner: "{{ web_user }}"
13+
group: "{{ web_group }}"
14+
mode: '0755'
15+
state: directory
16+
17+
- name: Download Matomo
18+
get_url:
19+
url: "{{ matomo_url }}"
20+
dest: "/tmp/matomo_latest.zip"
21+
22+
- name: Unzip Matomo
23+
unarchive:
24+
src: "/tmp/matomo_latest.zip"
25+
dest: "{{ addons_dir }}"
26+
remote_src: yes
27+
creates: "{{ addons_dir }}/matomo"
28+
29+
- name: Set ownership of Matomo files
30+
file:
31+
path: "{{ addons_dir }}/matomo"
32+
owner: "{{ matomo_owner }}"
33+
group: "{{ matomo_group }}"
34+
recurse: yes
35+
36+
- name: Ensure correct permissions on Matomo directory
37+
file:
38+
path: "{{ addons_dir }}/matomo"
39+
mode: '0755'
40+
recurse: yes
41+
42+
- name: Create Matomo database
43+
mysql_db:
44+
name: "{{ matomo_db_name }}"
45+
state: present
46+
login_host: "{{ site_env.db_host }}"
47+
login_user: "{{ mysql_root_user }}"
48+
login_password: "{{ mysql_root_password }}"
49+
with_dict: "{{ wordpress_sites }}"
50+
tags: matomo
51+
52+
- name: Create Matomo database user and grant permissions
53+
mysql_user:
54+
name: "{{ item.value.matomo.db.user }}"
55+
password: "{{ item.value.matomo.db.password }}"
56+
host: "{{ site_env.db_user_host }}"
57+
append_privs: yes
58+
priv: "{{ matomo_db_name }}.*:ALL"
59+
state: present
60+
login_host: "{{ site_env.db_host }}"
61+
login_user: "{{ mysql_root_user }}"
62+
login_password: "{{ mysql_root_password }}"
63+
with_dict: "{{ wordpress_sites }}"
64+
tags: matomo
65+
66+
- name: Create symlink to Matomo
67+
file:
68+
path: "{{ deploy_helper.new_release_path }}/web/analytics"
69+
src: "{{ addons_dir }}/matomo"
70+
state: link
71+
with_dict: "{{ wordpress_sites }}"
72+
tags: matomo
73+
74+
- name: Explain next steps
75+
debug:
76+
msg: |
77+
If necessary, set up Matomo as follows:
78+
1) Deploy
79+
2) Point your browser to {{ wordpress_env_defaults.wp_home }}/analytics
80+
3) Proceed with the form using following credentials:
81+
Host: {{ site_env.db_user_host }}
82+
Database User: {{ item.value.matomo.db.user }}
83+
Database Password: {{ item.value.matomo.db.password }}
84+
Database: {{ matomo_db_name }}
85+
Table Prefix: none
86+
Set up your admin user.
87+
4) Log in to Matomo.
88+
5) Under Administration/System/Geolocation, download and activate the GeoIP 2 database.
89+
with_dict: "{{ wordpress_sites }}"
90+
tags: matomo

tasks/nginx.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
- name: Configure Nginx for Matomo
3+
template:
4+
src: "nginx-matomo.conf.j2"
5+
dest: "/etc/nginx/sites-available/{{ site_host }}-matomo.conf"
6+
notify: reload nginx
7+
8+
- name: Enable Nginx site for Matomo
9+
file:
10+
src: "/etc/nginx/sites-available/{{ site_host }}-matomo.conf"
11+
dest: "/etc/nginx/sites-enabled/{{ site_host }}-matomo.conf"
12+
state: link
13+
notify: reload nginx

templates/nginx-matomo.conf.j2

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
server {
2+
listen 80;
3+
server_name {{ site_host }};
4+
root {{ addons_dir }}/matomo;
5+
6+
index index.php index.html index.htm;
7+
8+
access_log /srv/www/{{ site_host }}/logs/matomo-access.log;
9+
error_log /srv/www/{{ site_host }}/logs/matomo-error.log;
10+
11+
location / {
12+
try_files $uri $uri/ =404;
13+
}
14+
15+
location ~ \.php$ {
16+
include fastcgi_params;
17+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
18+
fastcgi_pass unix:/var/run/php/php{{ php_version }}-fpm.sock;
19+
}
20+
21+
location ~* \.(?:css|js|ico|gif|jpe?g|png)$ {
22+
expires max;
23+
add_header Cache-Control "public";
24+
}
25+
26+
location = /robots.txt {
27+
allow all;
28+
log_not_found off;
29+
access_log off;
30+
}
31+
}

0 commit comments

Comments
 (0)