From 7d141f6be3c6ed9c3eafcebd59edf0e0b2ada38c Mon Sep 17 00:00:00 2001 From: Marco Malavolti Date: Thu, 28 Nov 2019 12:49:31 +0100 Subject: [PATCH] Refactored issue #17 and fixed issue #18 --- roles/idp/tasks/idp-statistics.yml | 2 +- roles/idp/templates/statistics/dbanalysis.py.j2 | 2 +- roles/idp/templates/statistics/insertSP.php.j2 | 2 +- roles/idp/templates/statistics/statistics-idp-db.sql.j2 | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/roles/idp/tasks/idp-statistics.yml b/roles/idp/tasks/idp-statistics.yml index 4709938..eb1aaf0 100644 --- a/roles/idp/tasks/idp-statistics.yml +++ b/roles/idp/tasks/idp-statistics.yml @@ -22,7 +22,7 @@ - ansible_distribution_release == "stretch" - name: "Check if 'statistics' DB is already created and store the result into 'statistics_db' ansible variable" - command: mysql -h {{ idp_config['shibboleth_db_host'] }} -u statistics -p{{ idp_stats['db_pw'] }} -s -N -e "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME='statistics'" + command: mysql -h {{ idp_stats['db_host'] }} -u statistics -p{{ idp_stats['db_pw'] }} -s -N -e "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME='statistics'" register: statistics_db changed_when: false diff --git a/roles/idp/templates/statistics/dbanalysis.py.j2 b/roles/idp/templates/statistics/dbanalysis.py.j2 index 556f9f0..650feac 100644 --- a/roles/idp/templates/statistics/dbanalysis.py.j2 +++ b/roles/idp/templates/statistics/dbanalysis.py.j2 @@ -82,7 +82,7 @@ def parseFiles(files): else: dictAll[curdate][rp][user] = 1 - database = MySQLdb.connect(host="localhost", user="statistics", passwd="{{ idp_stats['db_pw'] }}", db="statistics") + database = MySQLdb.connect(host="{{ idp_stats['db_host'] }}", user="statistics", passwd="{{ idp_stats['db_pw'] }}", db="statistics") cursor = database.cursor() cursor.execute("SELECT MAX(data) FROM logins") diff --git a/roles/idp/templates/statistics/insertSP.php.j2 b/roles/idp/templates/statistics/insertSP.php.j2 index 22e5ebe..0953a3a 100644 --- a/roles/idp/templates/statistics/insertSP.php.j2 +++ b/roles/idp/templates/statistics/insertSP.php.j2 @@ -2,7 +2,7 @@ include "SProvider.conf.php"; include "SProvider.metadata.php"; -$db = mysqli_connect("localhost", "statistics", "{{ idp_stats['db_pw'] }}", "statistics"); +$db = mysqli_connect("{{ idp_stats['db_host'] }}", "statistics", "{{ idp_stats['db_pw'] }}", "statistics"); if (!$db){ die("Unable to connect to database 'statistics'"); diff --git a/roles/idp/templates/statistics/statistics-idp-db.sql.j2 b/roles/idp/templates/statistics/statistics-idp-db.sql.j2 index d39fc50..5fdbbde 100644 --- a/roles/idp/templates/statistics/statistics-idp-db.sql.j2 +++ b/roles/idp/templates/statistics/statistics-idp-db.sql.j2 @@ -4,7 +4,7 @@ SET CHARACTER SET utf8; CREATE DATABASE IF NOT EXISTS statistics CHARACTER SET=utf8; -GRANT ALL PRIVILEGES ON statistics.* TO statistics@localhost IDENTIFIED BY '{{ idp_stats['db_pw'] }}'; +GRANT ALL PRIVILEGES ON statistics.* TO statistics@{{ idp_stats['db_host'] }} IDENTIFIED BY '{{ idp_stats['db_pw'] }}'; FLUSH PRIVILEGES;