Skip to content

Commit 93b0702

Browse files
committed
First prototype
1 parent e70fa79 commit 93b0702

File tree

2 files changed

+75
-20
lines changed

2 files changed

+75
-20
lines changed

defaults/main.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
---
2-
addons_dir: "{{ project_root }}/addons"
2+
addons_dir: "{{ www_root }}/{{ item.key }}/addons"
3+
matomo_dir: "matomo"
4+
combined_wordpress_sites: "{{ wordpress_sites|combine(vault_wordpress_sites, recursive=True) }}"
35
matomo_url: "https://builds.matomo.org/matomo-latest.zip"
46
matomo_php_extensions:
57
- php{{ php_version }}-gd
@@ -10,4 +12,5 @@ matomo_php_extensions:
1012
- php{{ php_version }}-cli
1113
- php{{ php_version }}-mysql
1214
matomo_owner: "{{ web_user }}"
13-
matomo_group: "{{ web_group }}"
15+
matomo_group: "{{ web_group }}"
16+
matomo_db_name: "matomo_{{ env }}"

tasks/main.yml

+70-18
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,21 @@
66
with_items: "{{ matomo_php_extensions }}"
77
notify: reload php-fpm
88

9+
- name: Install PyMySQL
10+
apt:
11+
name: python3-pymysql
12+
state: present
13+
become: yes
14+
915
- name: Create addons folder for Matomo installation
1016
file:
1117
path: "{{ addons_dir }}"
1218
owner: "{{ web_user }}"
1319
group: "{{ web_group }}"
1420
mode: '0755'
1521
state: directory
22+
with_dict: "{{ wordpress_sites }}"
23+
no_log: true
1624

1725
- name: Download Matomo
1826
get_url:
@@ -24,20 +32,48 @@
2432
src: "/tmp/matomo_latest.zip"
2533
dest: "{{ addons_dir }}"
2634
remote_src: yes
27-
creates: "{{ addons_dir }}/matomo"
35+
creates: "{{ addons_dir }}/{{ matomo_dir }}"
36+
with_dict: "{{ wordpress_sites }}"
37+
no_log: true
38+
tags: matomo
39+
40+
- name: Delete the unzipped "How to install Matomo.html" file
41+
file:
42+
path: "{{ addons_dir }}/How to install Matomo.html"
43+
state: absent
44+
with_dict: "{{ wordpress_sites }}"
45+
no_log: true
46+
tags: matomo
2847

2948
- name: Set ownership of Matomo files
3049
file:
31-
path: "{{ addons_dir }}/matomo"
50+
path: "{{ addons_dir }}/{{ matomo_dir }}"
3251
owner: "{{ matomo_owner }}"
3352
group: "{{ matomo_group }}"
3453
recurse: yes
54+
with_dict: "{{ wordpress_sites }}"
55+
no_log: true
56+
tags: matomo
3557

3658
- name: Ensure correct permissions on Matomo directory
3759
file:
38-
path: "{{ addons_dir }}/matomo"
60+
path: "{{ addons_dir }}/{{ matomo_dir }}"
3961
mode: '0755'
4062
recurse: yes
63+
with_dict: "{{ wordpress_sites }}"
64+
no_log: true
65+
tags: matomo
66+
67+
- name: Check if Matomo variables are set for each site
68+
fail:
69+
msg: "Matomo database credentials are not set in your group_vars – please review and ensure these are configured for the site {{ item.key }}."
70+
when:
71+
- item.value.matomo is not defined
72+
- item.value.matomo.db is not defined
73+
- item.value.matomo.db.user is not defined or item.value.matomo.db.password is not defined
74+
with_dict: "{{ combined_wordpress_sites }}"
75+
no_log: true
76+
tags: matomo
4177

4278
- name: Create Matomo database
4379
mysql_db:
@@ -47,6 +83,7 @@
4783
login_user: "{{ mysql_root_user }}"
4884
login_password: "{{ mysql_root_password }}"
4985
with_dict: "{{ wordpress_sites }}"
86+
no_log: true
5087
tags: matomo
5188

5289
- name: Create Matomo database user and grant permissions
@@ -60,31 +97,46 @@
6097
login_host: "{{ site_env.db_host }}"
6198
login_user: "{{ mysql_root_user }}"
6299
login_password: "{{ mysql_root_password }}"
63-
with_dict: "{{ wordpress_sites }}"
100+
column_case_sensitive: true
101+
with_dict: "{{ combined_wordpress_sites }}"
102+
no_log: true
64103
tags: matomo
65104

66105
- name: Create symlink to Matomo
67106
file:
68-
path: "{{ deploy_helper.new_release_path }}/web/analytics"
69-
src: "{{ addons_dir }}/matomo"
107+
path: "{{ www_root }}/{{ item.key }}/{{ item.value.current_path | default('current') }}/{{ item.value.public_path | default('web') }}/{{ item.value.matomo.path | default('matomo') }}"
108+
src: "{{ addons_dir }}/{{ matomo_dir }}"
70109
state: link
71-
with_dict: "{{ wordpress_sites }}"
72-
tags: matomo
110+
loop: "{{ wordpress_sites | dict2items }}"
111+
loop_control:
112+
label: "{{ item.key }}"
73113

74114
- name: Explain next steps
75-
debug:
76-
msg: |
115+
pause:
116+
seconds: 0
117+
prompt: |
118+
======================
77119
If necessary, set up Matomo as follows:
120+
78121
1) Deploy
79-
2) Point your browser to {{ wordpress_env_defaults.wp_home }}/analytics
122+
123+
2) Point your browser to {{ wordpress_env_defaults.wp_home }}/{{ item.value.matomo.path | default('matomo') }}
124+
80125
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.
126+
127+
Host: {{ site_env.db_user_host }}
128+
Database User: {{ item.value.matomo.db.user }}
129+
Database Password: {{ item.value.matomo.db.password }}
130+
Database: {{ matomo_db_name }}
131+
Table Prefix: none
132+
Database Engine: MariaDB
133+
134+
Set up your admin user.
135+
87136
4) Log in to Matomo.
137+
88138
5) Under Administration/System/Geolocation, download and activate the GeoIP 2 database.
89-
with_dict: "{{ wordpress_sites }}"
139+
======================
140+
with_dict: "{{ combined_wordpress_sites }}"
141+
no_log: true
90142
tags: matomo

0 commit comments

Comments
 (0)