2022-05-01 10:09:49 +00:00
# The sections of code interacting with the Matomo website are modified from code found at https://git.coop/webarch/matomo/. This code is distributed under
# Version 3 of the GNU General Public License. We modified this code and applied it here in April 2022. The derived sections correspond to the tasks running
2022-06-15 06:40:28 +00:00
# from "HTTP Get Welcome" through "Finish Matomo Setup", lines 45 through 156.
2022-06-18 17:43:43 +00:00
- name : "WARNING: './runrole --reinstall matomo' CAN FAIL AS OF 2022-06-15, e.g. if /library/www/matomo already exists"
2022-06-15 06:40:28 +00:00
meta : noop
# EXAMPLE OF ABOVE ERROR:
# TASK [matomo : HTTP Get Welcome] ***************************************************************************************************************************************
# fatal: [127.0.0.1]: FAILED! => {"cache_control": "private, no-cache, no-store", "changed": false, "connection": "close", "content_type": "text/html; charset=utf-8", "date": "Wed, 15 Jun 2022 05:07:41 GMT", "elapsed": 0, "expires": "Thu, 19 Nov 1981 08:52:00 GMT", "msg": "Status code was 500 and not [200]: HTTP Error 500: Internal Server Error", "pragma": "no-cache", "redirected": false, "server": "nginx/1.18.0 (Ubuntu)", "set_cookie": "MATOMO_SESSID=psak3aem27vrdrt8t2f016600f; path=/; HttpOnly; SameSite=Lax", "status": 500, "transfer_encoding": "chunked", "url": "http://box.lan/matomo/index.php?action=welcome", "x_matomo_request_id": "fbfd2"}
2022-05-01 10:09:49 +00:00
2022-04-30 11:07:09 +00:00
- name : Start MariaDB
2022-06-15 06:40:28 +00:00
#action: service name=mysql state=started
systemd :
name : "{{ mysql_service }}"
state : started
2022-04-30 11:07:09 +00:00
- name : Create MariaDB Database for Matomo
community.mysql.mysql_db :
2022-06-15 06:40:28 +00:00
name : "{{ matomo_db_name }}"
#login_unix_socket: /var/run/mysqld/mysqld.sock
2022-04-30 11:07:09 +00:00
- name : Add Admin User to MariaDB Database
community.mysql.mysql_user :
2022-06-15 06:40:28 +00:00
name : "{{ matomo_db_user }}"
password : "{{ matomo_db_pass }}"
update_password : on_create # OR SHOULD './runrole --reinstall matomo' FORCE A COMPLETELY CLEAN INSTALL?
priv : "{{ matomo_db_name }}.*:ALL"
#login_unix_socket: /var/run/mysqld/mysqld.sock
- name : Download and Extract Matomo (~1 min)
2022-04-30 11:07:09 +00:00
unarchive :
2022-06-15 08:01:58 +00:00
src : "{{ matomo_dl_url }}" # e.g. https://builds.matomo.org/matomo.tar.gz
2022-06-18 17:43:43 +00:00
dest : "{{ matomo_path }}" # e.g. /library/www
2022-04-30 11:07:09 +00:00
remote_src : yes
2022-06-15 06:40:28 +00:00
2022-04-30 11:07:09 +00:00
- name : Set Matomo Directory Permissions
file :
2022-06-15 06:40:28 +00:00
path : "{{ matomo_path }}/matomo"
2022-04-30 11:07:09 +00:00
recurse : yes
2022-08-31 13:13:53 +00:00
owner : "{{ apache_user }}" # e.g. www-data
group : "{{ apache_user }}"
2022-06-15 06:40:28 +00:00
2022-04-30 11:07:09 +00:00
- name : HTTP Get Welcome
uri :
2022-06-15 06:40:28 +00:00
url : "{{ matomo_full_url }}index.php?action=welcome" # e.g. http://box.lan/matomo
2022-04-30 11:07:09 +00:00
method : GET
status_code : 200
register : matomo_welcome
2022-06-15 06:40:28 +00:00
- debug :
2022-05-31 10:51:57 +00:00
var : matomo_welcome
2022-06-15 06:40:28 +00:00
2022-04-30 11:07:09 +00:00
- name : Set a variable for the MATOMO_SESSID cookie
set_fact :
matomo_session_cookie : "MATOMO_SESSID={{ cookie.value }}"
when : cookie.key == "MATOMO_SESSID"
loop : "{{ matomo_welcome.cookies | dict2items }}"
loop_control :
loop_var : cookie
2022-06-15 06:40:28 +00:00
2022-04-30 11:07:09 +00:00
- name : Get Matomo System Check
uri :
2022-06-15 06:40:28 +00:00
url : "{{ matomo_full_url }}index.php?action=systemCheck"
2022-04-30 11:07:09 +00:00
method : GET
headers :
Cookie : "{{ matomo_session_cookie }}"
return_content : true
timeout : 120
status_code : 200
register : matomo_system_check
2022-06-15 06:40:28 +00:00
- debug :
2022-05-31 10:51:57 +00:00
var : matomo_system_check
2022-06-15 06:40:28 +00:00
2022-04-30 11:07:09 +00:00
- name : Matomo Database Setup
uri :
2022-06-15 06:40:28 +00:00
url : "{{ matomo_full_url }}index.php?action=databaseSetup"
2022-04-30 11:07:09 +00:00
method : POST
headers :
Cookie : "{{ matomo_session_cookie }}"
body :
2022-06-15 06:40:28 +00:00
username : "{{ matomo_db_user }}"
password : "{{ matomo_db_pass }}"
dbname : "{{ matomo_db_name }}"
2022-05-14 18:19:14 +00:00
tables_prefix : "matomo_"
2022-04-30 11:07:09 +00:00
adapter : "PDO\\MYSQL"
body_format : form-urlencoded
status_code : 302
2022-06-15 06:40:28 +00:00
#register: matomo_database_setup
2022-04-30 11:07:09 +00:00
- name : Matomo Table Creation
uri :
2022-06-15 06:40:28 +00:00
url : "{{ matomo_full_url }}index.php?action=tablesCreation&module=Installation"
2022-04-30 11:07:09 +00:00
method : GET
status_code : 200
register : matomo_table_creation
2022-06-15 06:40:28 +00:00
2022-05-31 10:51:57 +00:00
- name : Set a variable for the MATOMO_SESSID cookie
set_fact :
matomo_session_cookie : "MATOMO_SESSID={{ cookie.value }}"
when :
- matomo_table_creation.cookies is defined
- matomo_table_creation.cookies | length > 0
- cookie.key == "MATOMO_SESSID"
loop : "{{ matomo_table_creation.cookies | dict2items }}"
loop_control :
loop_var : cookie
2022-06-15 06:40:28 +00:00
- debug :
2022-05-31 10:51:57 +00:00
var : matomo_table_creation
2022-06-15 06:40:28 +00:00
2022-04-30 11:07:09 +00:00
- name : Matomo User Setup
uri :
2022-06-15 06:40:28 +00:00
url : "{{ matomo_full_url }}index.php?action=setupSuperUser&module=Installation"
2022-04-30 11:07:09 +00:00
method : POST
headers :
Cookie : "{{ matomo_session_cookie }}"
body :
2022-06-15 06:40:28 +00:00
login : "{{ matomo_db_user }}"
password : "{{ matomo_db_pass }}"
password_bis : "{{ matomo_db_pass }}"
2022-06-12 10:27:27 +00:00
email : "nobody@dev.null"
2022-04-30 11:07:09 +00:00
subscribe_newsletter_piwikorg : 0
subscribe_newsletter_professionalservices : 0
body_format : form-urlencoded
status_code : 302
2022-06-15 06:40:28 +00:00
#register: matomo_setup_superuser
2022-04-30 11:07:09 +00:00
- name : Configure Matomo to track IIAB
uri :
2022-06-15 06:40:28 +00:00
url : "{{ matomo_full_url }}index.php?action=firstWebsiteSetup&module=Installation"
2022-04-30 11:07:09 +00:00
method : POST
headers :
Cookie : "{{ matomo_session_cookie }}"
body :
2022-06-12 10:27:27 +00:00
siteName : "IIAB"
2022-06-15 06:40:28 +00:00
url : "{{ matomo_host_url }}"
2022-04-30 11:07:09 +00:00
ecommerce : 0
body_format : form-urlencoded
2022-08-31 12:02:04 +00:00
status_code : [ 200 , 302 ]
2022-08-31 10:42:47 +00:00
register : _result
- name : Fallback Configure Matomo to track IIAB
uri :
url : "{{ matomo_full_url }}index.php?action=firstWebsiteSetup&module=Installation"
method : POST
headers :
Cookie : "{{ matomo_session_cookie }}"
body :
siteName : "IIAB"
url : "{{ matomo_host_url }}"
timezone : "Europe/London"
ecommerce : 0
body_format : form-urlencoded
2022-04-30 11:07:09 +00:00
status_code : 302
2022-08-31 10:42:47 +00:00
when : _result.status == 200
2022-06-15 06:40:28 +00:00
2022-04-30 11:07:09 +00:00
- name : Matomo Tracking Code
uri :
2022-06-15 06:40:28 +00:00
url : "{{ matomo_full_url }}index.php?action=trackingCode&module=Installation&site_idSite=1&site_name={{ matomo_host_url }}"
2022-04-30 11:07:09 +00:00
method : GET
headers :
Cookie : "{{ matomo_session_cookie }}"
return_content : true
status_code : 200
2022-06-15 06:40:28 +00:00
#register: matomo_tracking_code
2022-04-30 11:07:09 +00:00
- name : Finish Matomo Setup
uri :
2022-06-15 06:40:28 +00:00
url : "{{ matomo_full_url }}index.php?action=finished&module=Installation"
2022-04-30 11:07:09 +00:00
method : POST
headers :
Cookie : "{{ matomo_session_cookie }}"
body :
do_not_track : 1
anonymise_ip : 1
submit : "Continue to Matomo"
body_format : form-urlencoded
status_code : 302
2022-06-15 06:40:28 +00:00
2022-04-30 11:07:09 +00:00
- name : Start Collecting Matomo Data
cron :
name : "MatomoDataIngestionOnReboot"
special_time : reboot
job : "{{ matomo_cronjob }}"
user : root
cron_file : "matomo_reboot"
2022-06-15 06:40:28 +00:00
2022-04-30 11:07:09 +00:00
- name : Run Daily Job Collecting Matomo Data
cron :
name : "DailyMatomoDataIngestion"
minute : "0"
hour : "0"
job : "{{ matomo_cronjob }}"
user : root
cron_file : "matomo_daily"
2022-06-15 06:40:28 +00:00
2022-12-24 15:30:47 +00:00
- name : Set Permissions for token.php
copy :
content : ""
dest : "{{ matomo_path }}/matomo/tmp/cache/token.php"
group : "{{ apache_user }}"
owner : "{{ apache_user }}"
2022-06-15 06:40:28 +00:00
2022-12-24 15:30:47 +00:00
- name : Set Permissions for tracker Directory
file :
path : "{{ matomo_path }}/matomo/tmp/cache/tracker"
state : directory
owner : "{{ apache_user }}"
group : "{{ apache_user }}"
2022-12-24 13:19:22 +00:00
2022-12-27 19:34:52 +00:00
- name : Don't Check for Trusted Host
ansible.builtin.lineinfile :
path : "{{ matomo_path }}/matomo/config/config.ini.php"
2022-12-27 20:20:22 +00:00
line : "enable_trusted_host_check\=0"
2022-12-27 20:02:38 +00:00
insertafter : "^\[General\]$"
2022-12-25 14:56:40 +00:00
2022-06-15 06:40:28 +00:00
# RECORD Matomo AS INSTALLED
- name : "Set 'matomo_installed: True'"
set_fact :
matomo_installed : True
- name : "Add 'matomo_installed: True' to {{ iiab_state_file }}"
lineinfile :
path : "{{ iiab_state_file }}" # /etc/iiab/iiab_state.yml
regexp : '^matomo_installed'
line: 'matomo_installed : True '