My question now, does that even make sense? And if, how could I achieve that? Since trellis always installs wordpress for a new configured site. Could that be somehow bypassed?
I suggest just trying one of those. Add it to Trellis like other Galaxy roles we have in requirements.yml. Then add the role to server.yml and customize the variables.
I added a few small roles to Trellis which does most of the job.
# group_vars/{staging & production}/wordpress_sites.yml
...
matomo:
db:
user: matomo
host: localhost
# group_vars/{staging & production}/vault.yml
...
matomo:
db:
password:
# server.yml
...
- { role: matomo, tags: [matomo] }
# roles/matomo/defaults/main.yml
combined_wordpress_sites: "{{ wordpress_sites|combine(vault_wordpress_sites, recursive=True) }}"
addons_dir: "{{ www_root }}/{{ item.key }}/addons"
matomo_db_name: "matomo_{{ env }}"
# roles/matomo/tasks/main.yml
- name: Install Matomo
composer:
command: require
arguments: piwik/piwik
working_dir: "{{ addons_dir }}"
with_dict: "{{ wordpress_sites }}"
tags: matomo
- name: Create databases for Matomo
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/assign database user to db 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: "{{ combined_wordpress_sites }}"
tags: matomo
- name: Change addons owner to web_user
file:
path: "{{ addons_dir }}"
owner: "{{ web_user }}"
group: "{{ web_group }}"
state: directory
recurse: yes
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: {{ matomo_db_name }}
Database User: {{ item.value.matomo.db.user }}
Database Password: {{ item.value.matomo.db.password }}
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: "{{ combined_wordpress_sites }}"
tags: matomo
# roles/deploy/defaults/main.yml
...
deploy_share_after:
- "{{ playbook_dir }}/deploy-hooks/share-after.yml"
# deploy-hooks/share-after.yml
- name: Create symlink to Matomo
file:
path: "{{ deploy_helper.new_release_path }}/web/analytics"
src: "{{ addons_dir }}/vendor/piwik/piwik"
state: link
with_items: "{{ wordpress_sites }}"
Install & deploy.
Connect to web and follow the installation assistant. This step is only necessary after the first install. It could be automated, but too much work for what it is.
Awesome Thanks so much for sharing, I’m not into Ansible (yet) and needed guidance, installs fine…!
I needed to create the addons_dir first though – how / where did you set that one up? I am now establishing the folder in roles/matomo/tasks/main.yml (btw: I changed the order of the DB details in the install instructions there to match Matomo’s input fields) and then I also needed to reference the directory in roles/deploy/defaults/main.yml explicitly otherwise the deploy will fail…
Out of curiosity, how does the compatibility with Trellis work using the ICTO/ansible-piwik role?
For deb-style dependencies (Ubuntu), php5 is used, while Trellis uses php7,
Matomo (ex Piwik) does work with PHP 7 just as well as with 5. ICTO/ansible-piwik seems out of date. Matomo moved to a new format for the geoip databases also.
I’d recommend building your own task based on the above comments.