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)
- 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
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
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[foo@localhost])
Failed to retrieve current state of resource: Execution of '/usr/bin/
mysql mysql -p -NBe select '1' from user where CONCAT(user, '@',
host) = 'foo@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[foo@localhost/
joomla01]) Dependency mysql_user[foo@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[foo@localhost/
joomla01]) Skipping because of failed dependencies
Jul 5 01:05:58 web-test01 puppetd[23778]: Finished catalog run in
16.55 seconds
=======================================
1) You need to define mrootpw as parameter on the type, so you receive the value from the manifest
2) $mrootpw is not ruby
3) putting the password on the commandline makes it public on the machine it is running as well as many log files. It'd be better to supply a --extra-defaults-file
> 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)
> # 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
> 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
> 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[foo@localhost]) > Failed to retrieve current state of resource: Execution of '/usr/bin/ > mysql mysql -p -NBe select '1' from user where CONCAT(user, '@', > host) = 'foo@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[foo@localhost/ > joomla01]) Dependency mysql_user[foo@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[foo@localhost/ > joomla01]) Skipping because of failed dependencies > Jul 5 01:05:58 web-test01 puppetd[23778]: Finished catalog run in > 16.55 seconds > =======================================
> thank you for your interest in working on puppet!
thank you for answer ;)
> 1) You need to define mrootpw as parameter on the type, so you receive
> the value from the manifest
I try:
1. Add parameter in puppet defenition in custom type
2. Add parametr in custom class
3. Add code in provider with global ruby value (@value)
It's not work (and i'm stupid :( )
> 2) $mrootpw is not ruby
I add it in puppet defenition
> 3) putting the password on the commandline makes it public on the
> machine it is running as well as many log files. It'd be better to
> supply a --extra-defaults-file
# this parses the
@@ -58,11 +58,11 @@
name = split_name(@resource[:name])
case name[:type]
when :user
- mysql "mysql", "-e", "INSERT INTO user (host, user) VALUES ('%s',
'%s')" % [
+ mysql "mysql", "-uroot -p"@resource[:rootpw], "-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", "-uroot -p"@resource[:rootpw], "-e", "INSERT INTO
db (host, user, db) VALUES ('%s', '%s', '%s')" % [
name[:host], name[:user], name[:db],
]
end
@@ -71,7 +71,7 @@
end
def destroy
- mysql "mysql", "-e", "REVOKE ALL ON '%s'.* FROM '%s@%s'" %
[ @resource[:privileges], @resource[:database], @resource[:name],
@resource[:host] ]
+ mysql "mysql", "-uroot -p"@resource[:rootpw], "-e", "REVOKE ALL ON
'%s'.* FROM '%s@%s'" % [ @resource[:privileges], @resource[:database],
@resource[:name], @resource[:host] ]
end
def row_exists?
@@ -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", "-uroot -p"@resource[:rootpw], "-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 "mysql", "-uroot -p"@resource[:rootpw], "-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 "mysql", "-uroot -p"@resource[:rootpw], "-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 "mysql", "-uroot -p"@resource[:rootpw], "-Be", stmt
mysql_flush
end
end
Index: mysql_user/mysql.rb
===================================================================
--- mysql_user/mysql.rb (revision 2995)
+++ mysql_user/mysql.rb (revision 3002)
@@ -32,14 +32,14 @@
}
end
- cmd = "#{command(:mysql)} -NBe 'select concat(user, \"@\", host),
password from user where concat(user, \"@\", host) = \"%s\"'" %
@resource[:name]
+ cmd = "#{command(:mysql)} "-uroot -p"@resource[:rootpw], -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?
@@ -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", "-uroot -p"@resource[:rootpw], "-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", "-uroot -p"@resource[:rootpw], "-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", "-uroot -p"@resource[:rootpw], "-NBe", "select
'1' from user where CONCAT(user, '@', host) = '%s'" %
@resource[:name]).empty?
end