Puppet cannot find custom functions

528 views
Skip to first unread message

Ben Lavender

unread,
Aug 5, 2009, 2:37:54 AM8/5/09
to Puppet Users
Hello,

I'm trying to do almost exactly what the cookbook at
http://reductivelabs.com/trac/puppet/wiki/WritingYourOwnFunctions is
doing, namely, adding a custom hash function to determine what time
cron should run.

However, I can't get puppet to find my function. I've got it
symlinked all over:

[root@nagios1 functions]# puppetmasterd --configprint libdir
/var/lib/puppet/lib
[root@nagios1 functions]# ls /var/lib/puppet/lib/puppet/parser/
functions/functions.rb
/var/lib/puppet/lib/puppet/parser/functions/functions.rb
[root@nagios1 functions]# ls /etc/puppet/modules/puppet/plugins/puppet/
parser/functions/functions.rb
/etc/puppet/modules/puppet/plugins/puppet/parser/functions/
functions.rb

The conents of the file are:
require 'digest/sha1'

module Puppet::Parser::Functions
newfunction(:minute_from_address, :type => :rvalue) do |args|
Digest::SHA1.hexdigest(lookupvar('ipaddress')).hex.to_i % 60
end
end


And the recipe calling it is:
class puppet {

cron { puppet:
command => "/etc/init.d/puppet once",
user => root,
minute => minute_from_address()
}
}


But all I ever get is:
Aug 4 22:29:19 toolbox puppetd[10730]: Could not retrieve catalog:
Unknown function minute_from_address at /etc/puppet/modules/puppet/
manifests/init.pp:16 on node xyz

Can someone tell me what I'm doing wrong here? According to the link
referenced above, puppet should be picking up functions in these
directories. Even better, is there an accepted way I can tell
puppetmasterd to look for functions in a particular place?

Larry Ludwig

unread,
Aug 5, 2009, 8:13:58 AM8/5/09
to puppet...@googlegroups.com
>
>
> Can someone tell me what I'm doing wrong here? According to the link
> referenced above, puppet should be picking up functions in these
> directories. Even better, is there an accepted way I can tell
> puppetmasterd to look for functions in a particular place?

Hi I assumed your issue is related to this?

http://projects.reductivelabs.com/issues/2494

-L

--
Larry Ludwig
Reductive Labs

Ben Lavender

unread,
Aug 5, 2009, 12:47:21 PM8/5/09
to Puppet Users
Perhaps this is the same issue, but the workaround does not seem to
work. Starting puppetmasterd with --libdir=/var/lib/puppet/lib does
not fix the problem.

S H

unread,
Aug 5, 2009, 5:26:51 PM8/5/09
to puppet...@googlegroups.com
On Wed, Aug 5, 2009 at 12:47 PM, Ben Lavender <blav...@gmail.com> wrote:

Perhaps this is the same issue, but the workaround does not seem to
work.  Starting puppetmasterd with --libdir=/var/lib/puppet/lib does
not fix the problem.

Silly question, but this bit me: are you running both puppetmaster and client with --pluginsync?

-Shawn

 

S H

unread,
Aug 5, 2009, 5:27:25 PM8/5/09
to puppet...@googlegroups.com
On Wed, Aug 5, 2009 at 5:26 PM, S H <shdas...@gmail.com> wrote:
On Wed, Aug 5, 2009 at 12:47 PM, Ben Lavender <blav...@gmail.com> wrote:

Perhaps this is the same issue, but the workaround does not seem to
work.  Starting puppetmasterd with --libdir=/var/lib/puppet/lib does
not fix the problem.

Silly question, but this bit me: are you running both puppetmaster and client with --pluginsync?

-Shawn

Pretend I didn't ask that. Functions only run on the puppetmaster. Nothing to see here.

-Shawn
 

Ben Lavender

unread,
Aug 6, 2009, 12:52:04 AM8/6/09
to Puppet Users
Actually, I take that back--it would not appear to be the same issue
as #2494 at all.

I also have the functions file in this directory:
/etc/puppet/modules/puppet/plugins/puppet/parser/functions/

That should have been loaded as well, according to
http://reductivelabs.com/trac/puppet/wiki/WritingYourOwnFunctions ,
but it was not. I'm starting to worry that I'm missing something
terribly simple and obvious.

Ben

Allan Marcus

unread,
Aug 12, 2009, 1:58:04 PM8/12/09
to puppet...@googlegroups.com
Is there a solution to this?

---
Thanks,

Allan Marcus
505-667-5666

Ben Lavender

unread,
Sep 15, 2009, 5:09:20 AM9/15/09
to Puppet Users
Just so that it gets onto the mailing list for the next poor guy
searching for this:

Functions need to be in a file of the same name, it would appear. I
can find nothing in the wiki that mentions this specifically, but
perhaps I did not look hard enough.

I renamed my file from functions.rb to minute_from_address.rb and it
worked immediately. The location of the file, /etc/puppet/modules/
puppet/plugins/puppet/parser/functions/ , was evidently fine the whole
time.

Ben

Ohad Levy

unread,
Sep 15, 2009, 5:14:42 AM9/15/09
to puppet...@googlegroups.com
On 9/15/09, Ben Lavender <blav...@gmail.com> wrote:

I renamed my file from functions.rb to minute_from_address.rb and it

Like a function that converts your  ip address into a "random" value?
see http://reductivelabs.com/trac/puppet/wiki/Recipes/cron in the Setting Cron using a Puppet custom function 

:)
Ohad


 


James Turnbull

unread,
Sep 15, 2009, 5:19:23 AM9/15/09
to puppet...@googlegroups.com
2009/9/15 Ben Lavender <blav...@gmail.com>:

>
> Just so that it gets onto the mailing list for the next poor guy
> searching for this:
>
> Functions need to be in a file of the same name, it would appear.  I
> can find nothing in the wiki that mentions this specifically, but
> perhaps I did not look hard enough.

It's in:

http://reductivelabs.com/trac/puppet/wiki/WritingYourOwnFunctions

"The name of the file you put your function into must be the same as
the name of function, otherwise it won't get automatically loaded.
This ''will'' bite you some day."

Regards

James Turnbull

--
Author of:
* Pro Linux Systems Administration (http://tinyurl.com/linuxadmin)
* Pulling Strings with Puppet (http://tinyurl.com/pupbook)
* Pro Nagios 2.0 (http://tinyurl.com/pronagios)
* Hardening Linux (http://tinyurl.com/hardeninglinux)

Reply all
Reply to author
Forward
0 new messages