Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
custom facts and types
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
sHaggY_caT  
View profile  
 More options Jul 4 2010, 5:07 pm
From: sHaggY_caT <galia....@gmail.com>
Date: Sun, 4 Jul 2010 14:07:33 -0700 (PDT)
Local: Sun, Jul 4 2010 5:07 pm
Subject: custom facts and types
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 { "${user}@${host}":
      password_hash => mysql_password($password),
      require => File["/root/.my.cnf"],
      mrootpw => $rpw,
    }

    mysql_grant { "${user}@${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[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
=======================================

where i'm wrong?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David Schmitt  
View profile  
 More options Jul 5 2010, 4:10 am
From: David Schmitt <da...@dasz.at>
Date: Mon, 05 Jul 2010 10:10:13 +0200
Local: Mon, Jul 5 2010 4:10 am
Subject: Re: [Puppet Users] custom facts and types
Hi,

thank you for your interest in working on puppet!

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

Best Regards and Good Luck, David Schmitt

On 7/4/2010 11:07 PM, sHaggY_caT wrote:

--
dasz.at OG              Tel: +43 (0)664 2602670     Web: http://dasz.at
Klosterneuburg                                         UID: ATU64260999

        FB-Nr.: FN 309285 g          FB-Gericht: LG Korneuburg


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
sHaggY_caT  
View profile  
 More options Jul 5 2010, 10:57 am
From: sHaggY_caT <galia....@gmail.com>
Date: Mon, 5 Jul 2010 07:57:36 -0700 (PDT)
Local: Mon, Jul 5 2010 10:57 am
Subject: Re: custom facts and types

> Hi,

> 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

How i may it? In irb? Or else?

New (also not work code) code is:

----!!!---plugins-----!!!!!--------

Index: mysql_grant/mysql.rb
===================================================================
--- mysql_grant/mysql.rb        (revision 2995)
+++ mysql_grant/mysql.rb        (revision 3002)
@@ -30,7 +30,7 @@
        commands :mysqladmin => '/usr/bin/mysqladmin'

        def mysql_flush
-               mysqladmin "flush-privileges"
+               mysqladmin "-uroot -p"@resource[:rootpw], "flush-privileges"
        end

        # 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

-       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]
+               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

        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", "-uroot -p"@resource[:rootpw], "-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 3002)
@@ -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
@@ -40,14 +40,14 @@
        end

        def create
-               mysqladmin "create", @resource[:name]
+               mysqladmin "-u root -p"@resource[:rootpw], "create",
@resource[:name]
        end
        def destroy
-               mysqladmin "-f", "drop", @resource[:name]
+               mysqladmin "-f", "-u root -p"@resource[:rootpw], "drop",
@resource[:name]
        end

        def exists?
-               if mysql("mysql", "-NBe", "show databases").match(/
^#{@resource[:name]}$/)
+               if mysql("-u root -p"@resource[:rootpw], "mysql", "-NBe", "show
databases").match(/^#{@resource[:name]}$/)
                        true
                else
                        false

----!!!----pliugins------!!---

----!!--manifests of puppet defenitions---!!---

define mysql::database($rpw=$mysql_rootpw, $ensure) {

  if $mysql_exists == "true" {
    mysql_database { $name:
      ensure => $ensure,
      require => File["/root/.my.cnf"],
      rootpw => $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 { "${user}@${host}":
      password_hash => mysql_password($password),
      require => File["/root/.my.cnf"],
      rootpw => $rpw,
    }

    mysql_grant { "${user}@${host}/${database}":
      privileges => $priv,
      require => File["/root/.my.cnf"],
      rootpw => $rpw,
    }
  }

}

----!!--manifests of puppet defenitions---!!---

---!!---logs of puppet on test host---!!---
Jul  5 18:47:42 web-test01 puppetd[22161]: (/File[/var/lib/puppet/lib/
puppet/type]/checksum) checksum changed '{mtime}Tue Jun 22 21:02:21
+0400 2010' to '{mtime}Mon Jul 05 18:38:23 +0400 2010'
Jul  5 18:47:42 web-test01 puppetd[22161]: (/File[/var/lib/puppet/lib/
puppet/type/mysql_database.rb]/checksum) checksum changed '{md5}
62412e643dffc7637074c06e139b306c' to '{md5}
efc943ecc167e8d8c816ad95aedce1d9'
Jul  5 18:47:42 web-test01 puppetd[22161]: (/File[/var/lib/puppet/lib/
puppet/type/mysql_user.rb]/checksum) checksum changed '{md5}
891c9ffb20aefbb4b33e440f2abc421c' to '{md5}
11d5879147da18b1799a23f0e90a8619'
Jul  5 18:47:42 web-test01 puppetd[22161]: (/File[/var/lib/puppet/lib/
puppet/type/mysql_grant.rb]/checksum) checksum changed '{md5}
fc49241017e5ff590591f830659b185e' to '{md5}
a109ef4c2aa760e0789a0def485bfeef'
Jul  5 18:47:44 web-test01 puppetd[22161]: (/File[/var/lib/puppet/lib/
puppet/provider/mysql_database]/checksum) checksum changed '{mtime}Thu
Jul 01 16:22:48 +0400 2010' to '{mtime}Mon Jul 05 17:57:45 +0400 2010'
Jul  5 18:47:44 web-test01 puppetd[22161]: (/File[/var/lib/puppet/lib/
puppet/provider/mysql_database/mysql.rb]/checksum) checksum changed
'{md5}64c884adf3be051e051330a8d84f7f33' to '{md5}
62586371690abedfd524f4605a92ff24'
Jul  5 18:47:44 web-test01 puppetd[22161]: (/File[/var/lib/puppet/lib/
puppet/provider/mysql_user]/checksum) checksum changed '{mtime}Thu Jul
01 16:22:51 +0400 2010' to '{mtime}Mon Jul 05 17:57:45 +0400 2010'
Jul  5 18:47:45 web-test01 puppetd[22161]: (/File[/var/lib/puppet/lib/
puppet/provider/mysql_user/mysql.rb]/checksum) checksum changed '{md5}
b1ca24019ff357a74d57202cbc399f33' to '{md5}
9faef5d1a719a9b4a739ae6018eebcb2'
Jul  5 18:47:45 web-test01 puppetd[22161]: (/File[/var/lib/puppet/lib/
puppet/provider/mysql_grant]/checksum) checksum changed '{mtime}Tue
Jun 22 21:02:29 +0400 2010' to '{mtime}Mon Jul 05 17:57:46 +0400 2010'
Jul  5 18:47:45 web-test01 puppetd[22161]: (/File[/var/lib/puppet/lib/
puppet/provider/mysql_grant/mysql.rb]/checksum) checksum changed '{md5}
a48e3c23fd8ce998096c097fc72e6c75' to '{md5}
c5f15238146a0e213b62dfb9ae6dec89'
!!!----see in this line---!!!-----
Jul  5 18:47:48 web-test01 puppetd[22161]: Could not retrieve catalog:
Invalid parameter 'rootpw' for type 'Mysql_user' at /var/lib/puppet/
modules/modules_development/mod_mysql/manifests/init.pp:336 on node ...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »