Skip to content
This repository has been archived by the owner on Oct 10, 2021. It is now read-only.

Adds support for using a remote database. #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dbernstein
Copy link

@dbernstein dbernstein commented Dec 9, 2019

GitHub Issue: N/A

  • Other Relevant Links (Google Groups discussion, related pull requests,
    Release pull requests, etc.)

What does this Pull Request do?

It allows the matomo database to live on a non-local database server.

What's new?

The parameters that allow for remote database creation and connection.

How should this be tested?

Set up a remote database server and specify the necessary parameter overrides.

Interested parties

Tag (@ mention) interested parties or, if unsure, @Islandora-Devops/committers

Copy link
Contributor

@dannylamb dannylamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple more spots to touch up:

I'm spinning up an environment now to confirm.

@dannylamb
Copy link
Contributor

dannylamb commented Jan 27, 2020

That solves some initial problems, but now the mysql db dump is not restoring properly. Despite having the mysql client installed on the matomo server, it's not able to find it. I'm at a loss as to why, and am toying with delegate_to and become to see if I can get it going.

@dannylamb
Copy link
Contributor

@dbernstein I managed to get this working, but had to adapt the commands to generate and import the sql dump like so:

- name: prepare mysql dump restore
  template:
    src: "matomo.sql.j2"
    dest: "/opt/matomo.sql"
    owner: "{{ matomo_user }}"
    group: "{{ matomo_user }}"
    force: no
  register: motomo_sql_dump_create
  delegate_to: "root@{{ matomo_db_host }}"

- name: restore dump
  mysql_db:
    name: "{{ matomo_db_name }}"
    target: "/opt/matomo.sql"
    state: import
    login_user: "{{ matomo_db_root_user }}"
    login_password:  "{{ matomo_db_root_password }}"
  ignore_errors: yes
  when: motomo_sql_dump_create | changed
  delegate_to: "root@{{ matomo_db_host }}"

I'm not entirely sure why I had to do that, as the mysql client exists on the server, and one could presumably pipe a file to it. But it's something. Open to suggestions on this one from folks. @Islandora-Devops/committers?

@dannylamb
Copy link
Contributor

Not sure what was going on before, but I've found I can successfully make it through mysql import if you add the proper packages for your distro. If you split out the db server, those packages aren't on the other server if you run the playbook.

diff --git a/tasks/main.yml b/tasks/main.yml
index 7389ffe..f2e0c1e 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -13,6 +13,17 @@
     httpd_conf_directory: "{{ __httpd_conf_directory }}"
   when: httpd_conf_directory is not defined
 
+- name: Define OS-specific matomo_packages to install
+  set_fact:
+    matomo_packages: "{{ __matomo_packages }}"
+  when: matomo_packages is not defined
+
+- name: Install requisite packages
+  package:
+    name: "{{ item }}"
+    state: present
+  with_items: "{{ matomo_packages }}"
+
 # Create database
 - include_tasks: db-mysql.yml
   tags:
diff --git a/vars/Debian.yml b/vars/Debian.yml
index 221db14..deee5d9 100644
--- a/vars/Debian.yml
+++ b/vars/Debian.yml
@@ -4,3 +4,7 @@ httpd_conf_directory_enabled: "{{httpd_conf_directory}}/conf-enabled"
 
 __matomo_user: www-data
 __httpd_conf_directory: /etc/apache2
+
+__matomo_packages:
+  - python-mysqldb
+  - mysql-client 
diff --git a/vars/RedHat.yml b/vars/RedHat.yml
index 2e115a6..2d8edda 100644
--- a/vars/RedHat.yml
+++ b/vars/RedHat.yml
@@ -4,3 +4,7 @@ httpd_conf_directory_enabled: "{{httpd_conf_directory}}/conf.d"
 
 __matomo_user: apache
 __httpd_conf_directory: /etc/httpd
+
+__matomo_packages:
+  - MySQL-python
+  - mysql

@dannylamb
Copy link
Contributor

@dbernstein If you can include those changes, I'd be happy to merge this in.

@elizoller
Copy link

@dbernstein are those changes going to be included?
I was able to use it to deploy Matomo to AWS RDS 👍

@dbernstein
Copy link
Author

@dbernstein I managed to get this working, but had to adapt the commands to generate and import the sql dump like so:

- name: prepare mysql dump restore
  template:
    src: "matomo.sql.j2"
    dest: "/opt/matomo.sql"
    owner: "{{ matomo_user }}"
    group: "{{ matomo_user }}"
    force: no
  register: motomo_sql_dump_create
  delegate_to: "root@{{ matomo_db_host }}"

- name: restore dump
  mysql_db:
    name: "{{ matomo_db_name }}"
    target: "/opt/matomo.sql"
    state: import
    login_user: "{{ matomo_db_root_user }}"
    login_password:  "{{ matomo_db_root_password }}"
  ignore_errors: yes
  when: motomo_sql_dump_create | changed
  delegate_to: "root@{{ matomo_db_host }}"

I'm not entirely sure why I had to do that, as the mysql client exists on the server, and one could presumably pipe a file to it. But it's something. Open to suggestions on this one from folks. @Islandora-Devops/committers?

@dannylamb : do these dump/restore tasks go in tasks/main.yml or tasks/db-mysql.yml?

@dannylamb
Copy link
Contributor

@dbernstein That was a red herring. You can safely ignore that comment. The patch alone should handle everything.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants