]> gitweb.fluxo.info Git - puppet-mysql.git/commitdiff
Setting root password
authorSilvio Rhatto <rhatto@riseup.net>
Tue, 19 Jan 2010 14:09:01 +0000 (12:09 -0200)
committerSilvio Rhatto <rhatto@riseup.net>
Tue, 19 Jan 2010 14:09:01 +0000 (12:09 -0200)
files/setmysqlpass.sh [new file with mode: 0644]
manifests/init.pp
templates/my.cnf.erb [new file with mode: 0644]

diff --git a/files/setmysqlpass.sh b/files/setmysqlpass.sh
new file mode 100644 (file)
index 0000000..586775e
--- /dev/null
@@ -0,0 +1,18 @@
+#!/bin/bash
+#
+# Set MySQL password.
+#
+
+CONF="/root/.my.cnf"
+
+# Check config file
+if [ ! -e "$CONF" ]; then
+  echo "File not found: $CONF"
+  exit 1
+fi
+
+# Get password from configuration
+passwd="`grep ^'password='` $CONF | cut -d '=' -f 2"
+
+# Set the password
+echo "USE mysql; UPDATE user SET Password=PASSWORD('$passwd') WHERE User='root' AND Host='localhost';" | /usr/bin/mysql -u root
index 58adab1d723fb4f7468d3e44773ad2d2eb8fe956..d498152ca29cd076519abd2092c3210496b99c5c 100644 (file)
@@ -1,5 +1,6 @@
 # Using recipe from
 # from http://reductivelabs.com/trac/puppet/wiki/Recipes/MySQLStoredConfiguration
+# and snippets from git://git.puppet.immerda.ch/module-mysql.git
 
 class mysql {
     package { "mysql-client":
@@ -18,4 +19,36 @@ class mysql::server inherits mysql {
         hasstatus       => true,
         require         => Package["mysql-server"],
     }
+
+    case $mysql_rootpw {
+        '': { fail("You need to define a mysql root password! Please set \$mysql_rootpw in your site.pp or host config") }
+    }
+
+    file{ '/usr/local/sbin/setmysqlpass.sh':
+        source  => "puppet://$server/modules/mysql/setmysqlpass.sh",
+        require => Package[mysql-server],
+        owner   => root, group => 0, mode => 0500;
+    } 
+
+    exec{'set_mysql_rootpw':
+        command => "/usr/local/sbin/setmysqlpass.sh",
+        unless  => "mysqladmin -uroot status > /dev/null",
+        require => [ File['/usr/local/sbin/setmysqlpass.sh'], Package[mysql-server] ],
+    }
+
+   mysql::cnf { "root":
+     home   => "/root",
+     passwd => $mysql_rootpw,
+   }
+
+   define mysql::cnf($home, $passwd) {
+     $mysql_passwd = $passwd
+     file { "$home/.my.cnf":
+       content => template('mysql/my.cnf.erb'),
+       require => [ Package[mysql-server] ],
+       owner   => root,
+       group   => 0,
+       mode    => 0400,
+     }
+   }
 }
diff --git a/templates/my.cnf.erb b/templates/my.cnf.erb
new file mode 100644 (file)
index 0000000..c56c89f
--- /dev/null
@@ -0,0 +1,4 @@
+[client]
+user=root
+host=localhost
+password=<%= mysql_passwd %>