diff options
author | mh <mh@immerda.ch> | 2013-05-20 14:32:43 +0200 |
---|---|---|
committer | mh <mh@immerda.ch> | 2013-05-20 14:32:43 +0200 |
commit | 86ef2c3dd27e2c05dd66ead59aaea49a5c01d258 (patch) | |
tree | fbc760012e0954b8b22f3418e608825a67f363b1 /lib/puppet/provider/mysql_user/mysql.rb | |
parent | 1e8e9f472c2321e0468b346653f1f3bc4403e318 (diff) |
use the defaults file if available
Diffstat (limited to 'lib/puppet/provider/mysql_user/mysql.rb')
-rw-r--r-- | lib/puppet/provider/mysql_user/mysql.rb | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/lib/puppet/provider/mysql_user/mysql.rb b/lib/puppet/provider/mysql_user/mysql.rb index e3908be..21a49d2 100644 --- a/lib/puppet/provider/mysql_user/mysql.rb +++ b/lib/puppet/provider/mysql_user/mysql.rb @@ -8,11 +8,23 @@ Puppet::Type.type(:mysql_user).provide(:mysql, commands :mysql => '/usr/bin/mysql' commands :mysqladmin => '/usr/bin/mysqladmin' + # Optional defaults file + def self.defaults_file + if File.file?("#{Facter.value(:root_home)}/.my.cnf") + "--defaults-file=#{Facter.value(:root_home)}/.my.cnf" + else + nil + end + end + def defaults_file + self.class.defaults_file + end + # retrieve the current set of mysql users def self.instances users = [] - cmd = "#{command(:mysql)} mysql -NBe 'select concat(user, \"@\", host), password from user'" + cmd = "#{command(:mysql)} #{defaults_file} mysql -NBe 'select concat(user, \"@\", host), password from user'" execpipe(cmd) do |process| process.each do |line| users << new( query_line_to_hash(line) ) @@ -31,13 +43,13 @@ Puppet::Type.type(:mysql_user).provide(:mysql, end def mysql_flush - mysqladmin "flush-privileges" + mysqladmin(defaults_file,"flush-privileges") end def query result = {} - cmd = "#{command(:mysql)} -NBe 'select concat(user, \"@\", host), password from user where concat(user, \"@\", host) = \"%s\"'" % @resource[:name] + cmd = "#{command(:mysql)} #{defaults_file} -NBe 'select concat(user, \"@\", host), password from user where concat(user, \"@\", host) = \"%s\"'" % @resource[:name] execpipe(cmd) do |process| process.each do |line| unless result.empty? @@ -51,17 +63,17 @@ Puppet::Type.type(:mysql_user).provide(:mysql, end def create - mysql "mysql", "-e", "create user '%s' identified by PASSWORD '%s'" % [ @resource[:name].sub("@", "'@'"), @resource.should(:password_hash) ] + mysql(defaults_file, "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(defaults_file, "mysql", "-e", "drop user '%s'" % @resource[:name].sub("@", "'@'")) mysql_flush end def exists? - not mysql("mysql", "-NBe", "select '1' from user where CONCAT(user, '@', host) = '%s'" % @resource[:name]).empty? + not mysql(defaults_file, "mysql", "-NBe", "select '1' from user where CONCAT(user, '@', host) = '%s'" % @resource[:name]).empty? end def password_hash @@ -69,7 +81,7 @@ Puppet::Type.type(:mysql_user).provide(:mysql, end def password_hash=(string) - mysql "mysql", "-e", "SET PASSWORD FOR '%s' = '%s'" % [ @resource[:name].sub("@", "'@'"), string ] + mysql(defaults_file, "mysql", "-e", "SET PASSWORD FOR '%s' = '%s'" % [ @resource[:name].sub("@", "'@'"), string ]) mysql_flush end end |