From 4ac24a174e51d519f5d49690b48e503caf0080e5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Felix=20D=C3=B6rre?= Date: Fri, 16 Jun 2017 23:36:24 +0200 Subject: [PATCH] upd: move quiz to postgres Note: this change does not migrate the data from the mysql database Change-Id: I00a85c38054c759a37fde05a5e0b9f32a16d66ec --- environments/production/manifests/ip.pp | 7 ++-- .../production/manifests/postgres-primary.pp | 15 ++++++++ environments/production/manifests/quiz.pp | 35 +++++++++---------- modules/quiz/templates/sq_config.epp | 5 ++- 4 files changed, 37 insertions(+), 25 deletions(-) diff --git a/environments/production/manifests/ip.pp b/environments/production/manifests/ip.pp index 8c13733..b6ad1dd 100644 --- a/environments/production/manifests/ip.pp +++ b/environments/production/manifests/ip.pp @@ -10,12 +10,9 @@ $ips = { $passwords = { postgres => { - gigi => 'gigi' - }, - quiz-mysql => { - root => 'root', + gigi => 'gigi', quiz => 'quiz' - } + }, } $testServer = 'false' diff --git a/environments/production/manifests/postgres-primary.pp b/environments/production/manifests/postgres-primary.pp index e90109f..076c4a8 100644 --- a/environments/production/manifests/postgres-primary.pp +++ b/environments/production/manifests/postgres-primary.pp @@ -28,4 +28,19 @@ node postgres-primary { address => "$gigi_ip/32", auth_method => 'md5', } + + postgresql::server::db { 'quiz': + require => Class['postgresql::server'], + user => 'quiz', + password => postgresql_password('quiz', $passwords[postgres][quiz]), + } + postgresql::server::pg_hba_rule { 'allow quiz to access its database': + require => Package['postgresql'], + description => "Open up PostgreSQL for access from quiz to its database", + type => 'host', + database => 'quiz', + user => 'quiz', + address => "${ips[quiz]}/32", + auth_method => 'md5', + } } diff --git a/environments/production/manifests/quiz.pp b/environments/production/manifests/quiz.pp index 70577ff..f576158 100644 --- a/environments/production/manifests/quiz.pp +++ b/environments/production/manifests/quiz.pp @@ -15,12 +15,6 @@ define teracara_quiz (){ package { 'apache2': ensure => 'installed', } - file {'/etc/apache2/sites-available/000-default.conf': - require => Package['apache2'], - ensure => 'file', - source => 'puppet:///modules/quiz/000-default.conf', - notify => Service['apache2'], - } file {'/etc/teracara-quiz/config.php': require => Package['teracara-quiz'], ensure => 'file', @@ -49,21 +43,24 @@ define teracara_quiz (){ source => ['puppet:///modules/nre/config/ca/root.crt'], show_diff => 'no' } - class {'::mysql::client': - package_name => 'mariadb-client' + exec { 'import quiz schema': + command => "/usr/bin/psql -U quiz -h ${ips[postgres]} < /usr/share/teracara-quiz/sql/db_postgresql.sql", + environment => ["PGPASSWORD=${passwords[postgres][quiz]}"], + unless => "/usr/bin/psql -U quiz -h ${ips[postgres]} -tc \"select * from pg_tables where schemaname='public';\" | /bin/grep -q '.'", + require => [Package['teracara-quiz']], + before => File['/etc/apache2/sites-available/000-default.conf'] + } + file {'/etc/apache2/sites-available/000-default.conf': + require => Package['apache2'], + ensure => 'file', + source => 'puppet:///modules/quiz/000-default.conf', + notify => Service['apache2'], } - class { '::mysql::server': - package_name => 'mariadb-server', - root_password => $passwords[quiz-mysql][root] + package{'mariadb-server': + ensure => 'purged' } - mysql::db { 'quiz': - require => Package['teracara-quiz'], - user => 'quiz', - password => $passwords[quiz-mysql][quiz], - host => 'localhost', - grant => ['SELECT', 'INSERT', 'UPDATE', 'DELETE'], - sql => '/usr/share/teracara-quiz/sql/db.sql', - import_timeout => 900, + package{'mariadb-client': + ensure => 'purged' } } node quiz{ diff --git a/modules/quiz/templates/sq_config.epp b/modules/quiz/templates/sq_config.epp index 35b0aad..5d9fb89 100644 --- a/modules/quiz/templates/sq_config.epp +++ b/modules/quiz/templates/sq_config.epp @@ -3,4 +3,7 @@ $sq_hostname='localhost'; $sq_dbname='quiz'; $sq_dbusername='quiz'; - $sq_dbpassword='<%=$passwords[quiz-mysql][quiz]%>'; + $sq_dbpassword='<%=$passwords[postgres][quiz]%>'; + $sq_dbdriver='pdo'; + $sq_dbport='5432'; + $sq_dbdsn='pgsql:host=' . $sq_hostname .';port=' .$sq_dbport .';dbname=' . $sq_dbname; -- 2.39.2