FAQ
hi,guys-

I have a mysql database which stores host informations,so I wrote a
function to get some values.

- Here is the function rb(this function should return the type I defined
in the database):

#hosttype.rb

require "mysql"

module Puppet::Parser::Functions

newfunction(:hosttype, :type => :rvalue, :doc => "Gets host type from
db.") do |args|

dbh = Mysql.real_connect("mysql_server_ip", "username", "password",
"puppet")

res = dbh.query("SELECT host_type FROM host_extra_info where
name='" + args[0] + "'")

# return res.fetch_row

puts res.fetch_row

res.free

dbh.close if dbh

end

end



- Also I wrote a .pp file to test it:

#/tmp/1.pp

$extraaaaa = hosttype("my_hostname")

notify { $extraaaaa: }


Test results(the red value is the query result from db):

[root@pm tmp]# puppet 1.pp

notice: server

notice: /Stage[main]//Notify[server]/message: defined 'message' as 'server'

notice: Finished catalog run in 0.06 seconds


It looks right,but when I use it in my module manifests,it didn't work!


- my custom module manifests:

#extracache.pp

class custom::extracache {

$extra_info = hosttype($hostname)

notify { test:

message => "$extra_info"

}



file { "/etc/puppet/host_extra_info.cache":

content => "$extra_info",

}

}


Puppet run results:

[root@pm tmp]# puppet agent --onetime --no-daemonize --verbose

info: Retrieving plugin

notice:
/File[/var/lib/puppet/lib/puppet/parser/functions/hosttype.rb]/content:
content changed '{md5}2493078b3c7e78b5c9e26b35bb1ccd85' to
'{md5}614766f30295d33d8d27fa6dab768cc4'

info: Loading downloaded plugin
/var/lib/puppet/lib/puppet/parser/functions/hosttype.rb

info: Caching catalog for xxxxxxx

info: Applying configuration version '1362562073'

notice:

notice: /Stage[main]/Custom::Extracache/Notify[test]/message: defined
'message' as ''

notice: Finished catalog run in 0.73 seconds


It becomes nil,and I just don't know why.


Any reply I will appreciate!

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com.
To post to this group, send email to puppet-users@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 2 | next ›
Discussion Overview
grouppuppet-users @
categoriespuppet
postedMar 7, '13 at 2:51a
activeMar 12, '13 at 1:10p
posts2
users2
websitepuppetlabs.com

2 users in discussion

Felix Frank: 1 post Nicolas: 1 post

People

Translate

site design / logo © 2022 Grokbase