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):


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",

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

# return res.fetch_row

puts res.fetch_row


dbh.close if dbh



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


$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:


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

content changed '{md5}2493078b3c7e78b5c9e26b35bb1ccd85' to

info: Loading downloaded plugin

info: Caching catalog for xxxxxxx

info: Applying configuration version '1362562073'


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 @
postedMar 7, '13 at 2:51a
activeMar 12, '13 at 1:10p

2 users in discussion

Felix Frank: 1 post Nicolas: 1 post



site design / logo © 2022 Grokbase