From ee94a2a56c73dc54439b34a58320c8c233ccdbd7 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 18 Oct 2007 11:54:23 +0200 Subject: mysql: flush privileges, autorequire, minor adjustments This commit executes a mysqladmin flush-privileges after every modification of users or grants, thereby enabling mysql to actually look at the changes too. grants now autorequire the appropriate db and user adjustet my site.pp for new types --- plugins/puppet/provider/mysql_grant/mysql.rb | 7 +++++++ plugins/puppet/provider/mysql_user/mysql.rb | 8 ++++++++ plugins/puppet/type/mysql_grant.rb | 17 +++++++++++++++-- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/plugins/puppet/provider/mysql_grant/mysql.rb b/plugins/puppet/provider/mysql_grant/mysql.rb index 9d900ec..93d7ecf 100644 --- a/plugins/puppet/provider/mysql_grant/mysql.rb +++ b/plugins/puppet/provider/mysql_grant/mysql.rb @@ -10,6 +10,11 @@ Puppet::Type.type(:mysql_grant).provide(:mysql) do desc "Uses mysql as database." commands :mysql => '/usr/bin/mysql' + commands :mysqladmin => '/usr/bin/mysqladmin' + + def mysql_flush + mysqladmin "flush-privileges" + end # this parses the def split_name(string) @@ -44,6 +49,7 @@ Puppet::Type.type(:mysql_grant).provide(:mysql) do name[:host], name[:user], name[:db], ] end + mysql_flush end end @@ -129,6 +135,7 @@ Puppet::Type.type(:mysql_grant).provide(:mysql) do stmt = stmt << set << where mysql "mysql", "-Be", stmt + mysql_flush end end diff --git a/plugins/puppet/provider/mysql_user/mysql.rb b/plugins/puppet/provider/mysql_user/mysql.rb index 8238620..adc46c3 100644 --- a/plugins/puppet/provider/mysql_user/mysql.rb +++ b/plugins/puppet/provider/mysql_user/mysql.rb @@ -6,6 +6,7 @@ Puppet::Type.type(:mysql_user).provide(:mysql, desc "Use mysql as database." commands :mysql => '/usr/bin/mysql' + commands :mysqladmin => '/usr/bin/mysqladmin' # retrieve the current set of mysql users def self.instances @@ -29,6 +30,10 @@ Puppet::Type.type(:mysql_user).provide(:mysql, } end + def mysql_flush + mysqladmin "flush-privileges" + end + def query result = {} @@ -47,10 +52,12 @@ Puppet::Type.type(:mysql_user).provide(:mysql, def create mysql "mysql", "-e", "create user '%s' identified by PASSWORD '%s'" % [ @resource[:name].sub("@", "'@'"), @resource.should(:password_hash) ] + mysql_flush end def destroy mysql "mysql", "-e", "drop user '%s'" % @resource[:name].sub("@", "'@'") + mysql_flush end def exists? @@ -63,6 +70,7 @@ Puppet::Type.type(:mysql_user).provide(:mysql, def password_hash=(string) mysql "mysql", "-e", "SET PASSWORD FOR '%s' = '%s'" % [ @resource[:name].sub("@", "'@'"), string ] + mysql_flush end end diff --git a/plugins/puppet/type/mysql_grant.rb b/plugins/puppet/type/mysql_grant.rb index 8a858e6..0d31df3 100644 --- a/plugins/puppet/type/mysql_grant.rb +++ b/plugins/puppet/type/mysql_grant.rb @@ -3,12 +3,25 @@ Puppet::Type.newtype(:mysql_grant) do @doc = "Manage a database user's rights." #ensurable + autorequire :mysql_db do + # puts "Starting db autoreq for %s" % self[:name] + reqs = [] + matches = self[:name].match(/^([^@]+)@([^\/]+)\/(.+)$/) + unless matches.nil? + reqs << matches[3] + end + # puts "Autoreq: '%s'" % reqs.join(" ") + reqs + end + autorequire :mysql_user do + # puts "Starting user autoreq for %s" % self[:name] reqs = [] - matches = self[:name].match(/^([^@]+)@([^\/]+)$/) + matches = self[:name].match(/^([^@]+)@([^\/]+).*$/) unless matches.nil? - reqs << "%s@%s" % [ matches[0], matches[1] ] + reqs << "%s@%s" % [ matches[1], matches[2] ] end + # puts "Autoreq: '%s'" % reqs.join(" ") reqs end -- cgit