Hi all,
I read today my first book about ruby, and try modify code:
http://github.com/camptocamp/puppet-mysql
Unfortunatly, creator of this code don't replay from my e-mail (may
be, he don't have free time)
I'm stupid about paramters in provider. I add:
_______________________________________________________
Index: mysql_grant/mysql.rb
===================================================================
--- mysql_grant/mysql.rb (revision 2995)
+++ mysql_grant/mysql.rb (revision 2996)
@@ -30,7 +30,7 @@
commands :mysqladmin => '/usr/bin/mysqladmin'
def mysql_flush
- mysqladmin "flush-privileges"
+ mysqladmin "-p", $mrootpw, "flush-privileges"
end
# this parses the
@@ -53,16 +53,16 @@
end
end
- def create_row
+ def create_row(mrootpw)
unless @resource.should(:privileges).empty?
name = split_name(@resource[:name])
case name[:type]
when :user
- mysql "mysql", "-e", "INSERT INTO user (host,
user) VALUES ('%s',
'%s')" % [
+ mysql "mysql", "-p", $mrootpw, "-e", "INSERT
INTO user (host,
user) VALUES ('%s', '%s')" % [
name[:host], name[:user],
]
when :db
- mysql "mysql", "-e", "INSERT INTO db (host,
user, db) VALUES
('%s', '%s', '%s')" % [
+ mysql "mysql", "-p", $mrootpw, "-e", "INSERT
INTO db (host, user,
db) VALUES ('%s', '%s', '%s')" % [
name[:host], name[:user], name[:db],
]
end
@@ -80,7 +80,7 @@
if name[:type] == :db
fields<< :db
end
- not mysql( "mysql", "-NBe", 'SELECT "1" FROM %s WHERE %s' %
[ name[:type], fields.map do |f| "%s = '%s'" % [f, name[f]] end.join('
AND ')]).empty?
+ not mysql( "mysql", "-p", $mrootpw, "-NBe", 'SELECT "1" FROM %s
WHERE %s' % [ name[:type], fields.map do |f| "%s = '%s'" % [f,
name[f]] end.join(' AND ')]).empty?
end
def all_privs_set?
@@ -102,9 +102,9 @@
case name[:type]
when :user
- privs = mysql "mysql", "-Be", 'select * from user where
user="%s"
and host="%s"' % [ name[:user], name[:host] ]
+ privs = mysql "-p", $mrootpw, "mysql", "-Be", 'select *
from user
where user="%s" and host="%s"' % [ name[:user], name[:host] ]
when :db
- privs = mysql "mysql", "-Be", 'select * from db where
user="%s"
and host="%s" and db="%s"' % [ name[:user], name[:host], name[:db] ]
+ privs = mysql "-p", $mrootpw, "mysql", "-Be", 'select *
from db
where user="%s" and host="%s" and db="%s"' % [ name[:user],
name[:host], name[:db] ]
end
if privs.match(/^$/)
@@ -150,7 +150,7 @@
# puts "set:", set
stmt = stmt<< set<< where
- mysql "mysql", "-Be", stmt
+ mysql "-p", $mrootpw, "mysql", "-Be", stmt
mysql_flush
end
end
Index: mysql_user/mysql.rb
===================================================================
--- mysql_user/mysql.rb (revision 2995)
+++ mysql_user/mysql.rb (revision 2996)
@@ -32,11 +32,11 @@
}
end
- def mysql_flush
- mysqladmin "flush-privileges"
+ def mysql_flush(mrootpw)
+ mysqladmin "-p", $mrootpw, "flush-privileges"
end
- def query
+ def query(mrootpw)
result = {}
cmd = "#{command(:mysql)} -NBe 'select concat(user, \"@\",
host),
password from user where concat(user, \"@\", host) = \"%s\"'" %
@resource[:name]
@@ -53,17 +53,17 @@
end
def create
- mysql "mysql", "-e", "create user '%s' identified by PASSWORD
'%s'"
% [ @resource[:name].sub("@", "'@'"),
@resource.should(:password_hash) ]
+ mysql "mysql", "-p", $mrootpw, "-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 "mysql", "-p", $mrootpw, "-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("mysql", "-p", $mrootpw, "-NBe", "select '1' from user
where CONCAT(user, '@', host) = '%s'" % @resource[:name]).empty?
end
def password_hash
@@ -71,7 +71,7 @@
end
def password_hash=(string)
- mysql "mysql", "-e", "SET PASSWORD FOR '%s' = '%s'" %
[ @resource[:name].sub("@", "'@'"), string ]
+ mysql "mysql", "-p", $mrootpw, "-e", "SET PASSWORD FOR '%s' =
'%s'"
% [ @resource[:name].sub("@", "'@'"), string ]
mysql_flush
end
end
Index: mysql_database/mysql.rb
===================================================================
--- mysql_database/mysql.rb (revision 2995)
+++ mysql_database/mysql.rb (revision 2996)
@@ -7,7 +7,7 @@
#commands :mysqladmin => '/usr/local/bin/mysqladmin'
#commands :mysql => '/usr/local/bin/mysql'
commands :mysql => '/usr/bin/mysql'
- commands :mysqladmin => '/usr/bin/mysqladmin'
+ commands :mysqladmin => '/usr/bin/mysqladmin'
# retrieve the current set of mysql users
def self.instances
____________________________________________
Also, i modify puppet defenitions:
==========================
define mysql::database($rpw=$mysql_rootpw, $ensure) {
if $mysql_exists == "true" {
mysql_database { $name:
ensure => $ensure,
require => File["/root/.my.cnf"],
mrootpw => $rpw,
}
}
}
define mysql::rights($rpw=$mysql_rootpw, $database, $user, $password,
$host="localhost", $ensure="present", $priv="all") {
if $mysql_exists == "true" and $ensure == "present" {
mysql_user { "${us...@${host}":
password_hash => mysql_password($password),
require => File["/root/.my.cnf"],
mrootpw => $rpw,
}
mysql_grant { "${us...@${host}/${database}":
privileges => $priv,
require => File["/root/.my.cnf"],
mrootpw => $rootpw,
}
}
}
==============
I add my variable, mrootpw. But, ruby don't provide value variable in
my custom provider/type:
Jul 5 01:05:42 web-test01 puppetd[23778]: Could not prefetch
mysql_user provider 'mysql': #<IO:0xb7c5bf40>
Jul 5 01:05:56 web-test01 puppetd[23778]: (//Node[web-test01.int.ha-
systems.ru]/Mysql::Rights[joom_user01]/mysql_user[...@localhost])
Failed to retrieve current state of resource: Execution of '/usr/bin/
mysql mysql -p -NBe select '1' from user where CONCAT(user, '@',
host) = 'f...@localhost'' returned 1: /usr/bin/mysql Ver 14.12 Distrib
5.0.77, for redhat-linux-gnu (i686) using readline 5.1 Copyright (C)
2000-2008 MySQL AB This software comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to modify and redistribute
it under the GPL license Usage: /usr/bin/mysql [OPTIONS] [database]
-?, --help Display this help and exit. -I, --help
Synonym for -? --auto-rehash Enable automatic rehashing. One
doesn't need to use 'rehash' to get table and
field completion, but startup and reconnecting
may take a longer time. Disable with --disable-
auto-rehash. -A, --no-auto-rehash No auto
Jul 5 01:05:56 web-test01 puppetd[23778]: (//Node[web-test01.int.ha-
systems.ru]/Mysql::Rights[joom_user01]/mysql_grant[...@localhost/
joomla01]) Dependency mysql_user[...@localhost] has 1 failures
Jul 5 01:05:56 web-test01 puppetd[23778]: (//Node[web-test01.int.ha-
systems.ru]/Mysql::Rights[joom_user01]/mysql_grant[...@localhost/
joomla01]) Skipping because of failed dependencies
Jul 5 01:05:58 web-test01 puppetd[23778]: Finished catalog run in
16.55 seconds
=======================================
where i'm wrong?