diff options
Diffstat (limited to 'manifests/init.pp')
-rw-r--r-- | manifests/init.pp | 151 |
1 files changed, 145 insertions, 6 deletions
diff --git a/manifests/init.pp b/manifests/init.pp index 007d4c5..38ae339 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -2,27 +2,166 @@ # Copyright (C) 2007 David Schmitt <david@schmitt.edv-bus.at> # See LICENSE for the full license granted to you. +import "variables.pp" +import "passwords" + class mysql::server { + include passwords + include variables package { "mysql-server": name => "MySQL-server-community", ensure => installed, } - package { "mysql": + package { "mysql-client": name => "MySQL-client-community", ensure => installed, } - service { mysql: + service { "mysql": ensure => running, hasstatus => true, require => Package["mysql-server"], } - # Collect all databases and users - Mysql_database<<||>> - Mysql_user<<||>> - Mysql_grant<<||>> + # It is more convenient to set the root password with + # and exec than using the plugin + + $mysql_root_user = $variables::mysql_root_user + $mysql_root_database = $variables::mysql_root_database + $mysql_root_password = $passwords::mysql_root_password + $mysql_root_local_host = $variables::mysql_root_local_host + $mysql_global_host = $variables::mysql_global_host + + $mysql_replication_user = $variables::mysql_replication_user + $mysql_replication_password = $passwords::mysql_replication_password + + + $mysql_cmd_root_without_pwd = "/usr/bin/mysql --user=$mysql_root_user --database=$mysql_root_database --host=$mysql_root_local_host" + $mysql_cmd_root_with_pwd = "/usr/bin/mysql --user=$mysql_root_user --database=$mysql_root_database --host=$mysql_root_local_host --password=$mysql_root_password" + $mysql_cmd_repl_with_pwd = "/usr/bin/mysql --user=$mysql_replication_user --database=$mysql_root_database --host=$mysql_root_local_host --password=$mysql_replication_password" + + exec { "mysql root password init": + command => "$mysql_cmd_root_without_pwd --execute=\"Update user set password=password('$mysql_root_password') where user='$mysql_root_user';\"", + unless => "$mysql_cmd_root_with_pwd --execute '\s'", + require => Service["mysql"], + } + + exec { "mysql root flush password": + command => "$mysql_cmd_root_without_pwd --execute=\"flush privileges;\"", + unless => "$mysql_cmd_root_with_pwd --execute '\s'", + require => Exec["mysql root password init"], + } + + exec {"mysql create replication user": + command => "$mysql_cmd_root_with_pwd --execute=\"Create user '$mysql_replication_user'@'$mysql_global_host' identified by '$mysql_replication_password';\"", + unless => "$mysql_cmd_repl_with_pwd --execute '\s'", + require => Exec["mysql root flush password"], + } + + exec { "grants all to replication user": + command => "$mysql_cmd_root_with_pwd --execute=\"GRANT All PRIVILEGES ON *.* TO '$mysql_replication_user'@'$mysql_global_host' IDENTIFIED BY '$mysql_replication_password';\"", + unless => "$mysql_cmd_repl_with_pwd --execute '\s'", + require => Exec["mysql create replication user"], + } + + exec { "mysql root flush grants": + command => "$mysql_cmd_root_without_pwd --execute=\"flush privileges;\"", + unless => "$mysql_cmd_root_with_pwd --execute '\s'", + require => Exec["grants all to replication user"], + } + +} + +class mysql::standalone inherits mysql::server { + $binary_logging = false + $server_id = "1" + file { "/etc/my.cnf": + ensure => present, + owner => "mysql", + group => "mysql", + mode => 0644, + content => template("mysql/my.cnf.erb"), + before => Service["mysql"], + } +} + +class mysql::master inherits mysql::server { + $binary_logging = true + $server_id = $variables::mysql_master_server_id + + file { "/etc/my.cnf": + ensure => present, + owner => "mysql", + group => "mysql", + mode => 0644, + content => template("mysql/my.cnf.erb"), + before => Service["mysql"], + } +} + +class mysql::slave inherits mysql::server { + $binary_logging = true + $server_id = $variables::mysql_slave_server_id + $master_host_ip ='10.11.227.42' + + file { "/etc/my.cnf": + ensure => present, + owner => "mysql", + group => "mysql", + mode => 0644, + content => template("mysql/my.cnf.erb"), + before => Service["mysql"], + } + + file { "/var/lib/mysql/gather_master_data.bash": + owner => "mysql", + group => "mysql", + ensure => present, + mode => 0755, + content => template("mysql/gather_master_data.bash.erb"), +# source => "puppet://$puppetserver/mysql/gather_master_data.bash", + require => Exec["grants all to replication user"], + } + + exec { "set master data for slave": + command => "/var/lib/mysql/gather_master_data.bash", + creates => "/var/lib/mysql/set_master_repl_data.sql", + require => File["/var/lib/mysql/gather_master_data.bash"], + } + + exec { "start slave server": + command => "$mysql_cmd_repl_with_pwd --execute=\"start slave;\"", + unless => "$mysql_cmd_repl_with_pwd --execute=\"show slave status;\" | grep Wait", + require => Exec["set master data for slave"], + } +} + +define mysql::datasource($rootpw, $ds_name, $ds_owner, $ds_owner_pwd, $ds_user, $ds_user_pwd, $ds_schema) { + # TODO: This will soon be replaced. + # The execs will selectively run based on the value of $mysql_type + include mysql::standalone + + $mysql_root_cmd = "/usr/bin/mysql -u root -p$rootpw" + exec { "create datasource $ds_name": + command => "/usr/bin/mysqladmin -u root -p$rootpw create $ds_name", + unless => "$mysql_root_cmd $ds_name -e '\s'", + require => [Service["mysql"], Exec["mysql root password init"]], + } + + exec { "create grants $ds_name": + command => "$mysql_root_cmd -e \"GRANT ALL PRIVILEGES ON *.* TO '$ds_owner'@'%' IDENTIFIED BY '$ds_owner_pwd' WITH GRANT OPTION;\"", + unless => "/usr/bin/mysql --host $ipaddress --user=$ds_owner -password=$ds_password -e '\s'", + require => [Service["mysql"], Exec["mysql root password init"]], + } + # Only create the schema is a template directory was specified + if $ds_schema { + exec { "create db $ds_name": + command => "$mysql_root_cmd $ds_name < $ds_schema > /var/lib/mysql/${ds_name}-create-db.log", + creates => "/var/lib/mysql/${ds_name}-create-db.log", + require => [Service["mysql"], Exec["create datasource $ds_name"]], + } + } } |