Skip to content

Commit

Permalink
First prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
E-VANCE committed Oct 11, 2024
1 parent e70fa79 commit 93b0702
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 20 deletions.
7 changes: 5 additions & 2 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
addons_dir: "{{ project_root }}/addons"
addons_dir: "{{ www_root }}/{{ item.key }}/addons"
matomo_dir: "matomo"
combined_wordpress_sites: "{{ wordpress_sites|combine(vault_wordpress_sites, recursive=True) }}"
matomo_url: "https://builds.matomo.org/matomo-latest.zip"
matomo_php_extensions:
- php{{ php_version }}-gd
Expand All @@ -10,4 +12,5 @@ matomo_php_extensions:
- php{{ php_version }}-cli
- php{{ php_version }}-mysql
matomo_owner: "{{ web_user }}"
matomo_group: "{{ web_group }}"
matomo_group: "{{ web_group }}"
matomo_db_name: "matomo_{{ env }}"
88 changes: 70 additions & 18 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@
with_items: "{{ matomo_php_extensions }}"
notify: reload php-fpm

- name: Install PyMySQL
apt:
name: python3-pymysql
state: present
become: yes

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

- name: Download Matomo
get_url:
Expand All @@ -24,20 +32,48 @@
src: "/tmp/matomo_latest.zip"
dest: "{{ addons_dir }}"
remote_src: yes
creates: "{{ addons_dir }}/matomo"
creates: "{{ addons_dir }}/{{ matomo_dir }}"
with_dict: "{{ wordpress_sites }}"
no_log: true
tags: matomo

- name: Delete the unzipped "How to install Matomo.html" file
file:
path: "{{ addons_dir }}/How to install Matomo.html"
state: absent
with_dict: "{{ wordpress_sites }}"
no_log: true
tags: matomo

- name: Set ownership of Matomo files
file:
path: "{{ addons_dir }}/matomo"
path: "{{ addons_dir }}/{{ matomo_dir }}"
owner: "{{ matomo_owner }}"
group: "{{ matomo_group }}"
recurse: yes
with_dict: "{{ wordpress_sites }}"
no_log: true
tags: matomo

- name: Ensure correct permissions on Matomo directory
file:
path: "{{ addons_dir }}/matomo"
path: "{{ addons_dir }}/{{ matomo_dir }}"
mode: '0755'
recurse: yes
with_dict: "{{ wordpress_sites }}"
no_log: true
tags: matomo

- name: Check if Matomo variables are set for each site
fail:
msg: "Matomo database credentials are not set in your group_vars – please review and ensure these are configured for the site {{ item.key }}."
when:
- item.value.matomo is not defined
- item.value.matomo.db is not defined
- item.value.matomo.db.user is not defined or item.value.matomo.db.password is not defined
with_dict: "{{ combined_wordpress_sites }}"
no_log: true
tags: matomo

- name: Create Matomo database
mysql_db:
Expand All @@ -47,6 +83,7 @@
login_user: "{{ mysql_root_user }}"
login_password: "{{ mysql_root_password }}"
with_dict: "{{ wordpress_sites }}"
no_log: true
tags: matomo

- name: Create Matomo database user and grant permissions
Expand All @@ -60,31 +97,46 @@
login_host: "{{ site_env.db_host }}"
login_user: "{{ mysql_root_user }}"
login_password: "{{ mysql_root_password }}"
with_dict: "{{ wordpress_sites }}"
column_case_sensitive: true
with_dict: "{{ combined_wordpress_sites }}"
no_log: true
tags: matomo

- name: Create symlink to Matomo
file:
path: "{{ deploy_helper.new_release_path }}/web/analytics"
src: "{{ addons_dir }}/matomo"
path: "{{ www_root }}/{{ item.key }}/{{ item.value.current_path | default('current') }}/{{ item.value.public_path | default('web') }}/{{ item.value.matomo.path | default('matomo') }}"
src: "{{ addons_dir }}/{{ matomo_dir }}"
state: link
with_dict: "{{ wordpress_sites }}"
tags: matomo
loop: "{{ wordpress_sites | dict2items }}"
loop_control:
label: "{{ item.key }}"

- name: Explain next steps
debug:
msg: |
pause:
seconds: 0
prompt: |
======================
If necessary, set up Matomo as follows:
1) Deploy
2) Point your browser to {{ wordpress_env_defaults.wp_home }}/analytics
2) Point your browser to {{ wordpress_env_defaults.wp_home }}/{{ item.value.matomo.path | default('matomo') }}
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.
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
Database Engine: MariaDB
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 }}"
======================
with_dict: "{{ combined_wordpress_sites }}"
no_log: true
tags: matomo

0 comments on commit 93b0702

Please # to comment.