diff --git a/defaults/main.yml b/defaults/main.yml index 2085b2f..75c2e11 100755 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -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 @@ -10,4 +12,5 @@ matomo_php_extensions: - php{{ php_version }}-cli - php{{ php_version }}-mysql matomo_owner: "{{ web_user }}" -matomo_group: "{{ web_group }}" \ No newline at end of file +matomo_group: "{{ web_group }}" +matomo_db_name: "matomo_{{ env }}" \ No newline at end of file diff --git a/tasks/main.yml b/tasks/main.yml index 4917162..dd814eb 100755 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -6,6 +6,12 @@ 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 }}" @@ -13,6 +19,8 @@ group: "{{ web_group }}" mode: '0755' state: directory + with_dict: "{{ wordpress_sites }}" + no_log: true - name: Download Matomo get_url: @@ -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: @@ -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 @@ -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