Check this:

http://docs.puppetlabs.com/guides/custom_functions.html#calling-functions-from-functions



On Thu, Oct 17, 2013 at 12:08 AM, Sans <[email protected]> wrote:
>
> I just modified your code a little bit and created two function out of that:
>
>
> # am_running_oss_hash.rb
>>
>> module Puppet::Parser::Functions
>>     newfunction(:am_running_oss_hash, :type => :rvalue ) do |args|
>>
>>         inFile = args[0]
>>         gos = {}
>>
>>         if File.exist?(inFile)
>>             open(inFile, 'r').each do |line|
>>                 next if line =~ /^\s*(#|$)/
>>                 parts = line.split(',').map(&:strip)
>>
>>                 case parts[1]
>>                 when /^Mac/
>>                     (gos[:mac] ||= []) << parts[0]
>>                 when /_Win$/
>>                     (gos[:win] ||= []) << parts[0]
>>                 else
>>                     (gos[:linux] ||= []) << parts[0]
>>                 end
>>             end
>>         end
>>
>>         return gos
>>     end
>> end
>
>
>
> # am_running_oss.rb
>>
>> module Puppet::Parser::Functions
>>     newfunction(:am_running_oss, :type => :rvalue ) do |args|
>>         #Puppet::Parser::Functions.function('am_running_oss_hash')
>>         Puppet::Parser::Functions.autoloader.loadall
>>
>>         oss = function_am_running_oss_hash(['/tmp/OSs.txt'])
>>         if oss.count >= 1
>>              return oss.keys.join(',')
>>
>>         else
>>              return 'undefined'
>>         end
>>     end
>> end
>
>
>
> and then in the module:
>
>> $h = am_running_oss()
>> notify {"=*=*= RunnigOSS <|:|> ${h} =*=*=*=*=*=*=*=":}
>
>
>
> but I'm getting this error:
>
>> Error: Could not retrieve catalog from remote server: Error 400 on SERVER:
>> custom functions must be called with a single array that contains the
>> arguments. For example, function_example([1]) instead of function_example(1)
>
>
>
> What am I doing wrong? Cheers!!
>
>
>
> On Wednesday, October 16, 2013 11:45:42 AM UTC+1, Cristian Falcas wrote:
>>
>> You could return a hash, or an array if you need multiple from the
>> function.
>>
>>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/puppet-users.
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/puppet-users.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to