puppet custom function throwing private gsub error

104 views
Skip to first unread message

mohammad kashif

unread,
Feb 12, 2014, 8:21:30 AM2/12/14
to puppet...@googlegroups.com
I have written a small custom function to replace '.' to '_' of all element of an array and return an converted array.

module Puppet::Parser::Functions
  newfunction(:convert_vo, :type => :rvalue, :doc => <<-'ENDOFDOC'
 This function takes an array of vo and replace '.' with '_' and return an converted array
ENDOFDOC
  ) do |arguments|

    require 'rubygems'
    vo_list = arguments.clone
    unless vo_list.is_a?(Array)
      raise(Puppet::ParseError, 'convert_vo requires an array')
    end
    converted_vo = Array.new()
    vo_list.each do |vo|
      converted_vo.push(vo.gsub(/\./, '_'))
    end
    return converted_vo
  end
end

I am calling it like this from init.p

$vo = ['dteam', 'vo.southgrid.ac.uk']
$converted_vo = convert_vo($vo)


Puppet run on client machine fails with this error

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: private method `gsub' called for ["dteam", "vo.southgrid.ac.uk"]:Array at /etc/puppet/modules/voms_client/manifests/init.pp


I ran this script on client and server machines seperately and it worked perfectly. I am not sure that what I am missing?

Thanks
Kashif




Rafael Cristaldo

unread,
Feb 12, 2014, 9:15:19 AM2/12/14
to puppet...@googlegroups.com

Did you do this?
 

In order to make your custom functions available to your puppetmaster:

  • Place the function in a MODULEPATH/MODULENAME/lib/puppet/parser/functions directory.
  • Enable pluginsync in /etc/puppet/puppet.conf on client and server.
[main]
    pluginsync = true
    factpath = $vardir/lib/facter

kashif

unread,
Feb 12, 2014, 9:51:32 AM2/12/14
to puppet...@googlegroups.com
Hi Rafael

Yes, I have setup all paths  correctly. I have other custom functions which are working.

Thanks
Kashif

jcbollinger

unread,
Feb 13, 2014, 10:33:26 AM2/13/14
to puppet...@googlegroups.com


I'm not sure what you mean by "I ran this script", but your function is buggy.  The error message tells you exactly what the problem is: you are trying to invoke a method named 'gsub' on an object of type Array (which has no such method).

The function seems to be getting its nesting levels wrong.  The 'arguments' object passed into it is an array of the arguments to the function.  You call it with one argument, itself an array.  In your particular case, the value of 'arguments' seen by the function is [ [ 'dteam', 'vo.southgrid.ac.uk' ] ].  The function assumes that each element of 'arguments' supports a gsub() method, but that is not the case.

Among your alternatives are
  • don't wrap the function arguments in an array
  • make the function recognize array arguments and handle them appropriately

John

kashif

unread,
Feb 14, 2014, 6:37:33 AM2/14/14
to puppet...@googlegroups.com

Hi John

Thanks a lot. I misunderstood 'arguments' as an array of elements rather than array of 'arguments'.

Cheers
Kashif
Reply all
Reply to author
Forward
0 new messages