Hi John,

Thanks for the pointer, for workaround I used the inline_template function to work. Thanks for the piece of code. I will try this once I reach office, that would be on Monday.


On Fri, Nov 7, 2014 at 7:41 PM, jcbollinger <john.bollin...@stjude.org> wrote:


On Friday, November 7, 2014 5:15:23 AM UTC-6, Ashish Jaiswal wrote:
Hello,

Just trying to write a custom function. Basically looking to pass an
argument from manifest and value should get calculated.

module Puppet::Parser::Functions
         newfunction(:shmmax, :type => :rvalue) do |args|
                 def shmmax(args)
                         product = args * 1024 * 1024 * 1024
                         return product
                 end
         end
end


@ foo.pp
     $shmmax_variable = shmmax(2)
sysctl { "kernel.shmmax" : val => $shmmax_variable }

In this case I'm expecting a value of 2147483648 for kernel.shmmax in
sysctl.conf file

Its just fails, Any pointer what is wrong here ?


Your custom function does not have the necessary form. Most significantly, the block passed to newfunction() should perform the work of the function directly, not define a Ruby method to perform that work. For rvalue functions, the value obtained by executing the block is the return value of the function. Secondarily, the function arguments are presented to the function body as an array. For example,

module Puppet::Parser::Functions
    newfunction(:shmmax, :type => :rvalue) do |args|
        args[0] * 1024 * 1024 * 1024
    end
end

Note that if you want to perform any argument validation then that's on you.

Note also that the function must appear in a Ruby file with the same base name as the function itself, and that although you should put your function in a module, you need to sync it into the master's lib directory before the master will use it. Furthermore, be aware that if you change the function implementation then you must both sync the new function implementation into the master and restart the master, in that order, before your changes are effective.


John

--
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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/aa7cab69-49cd-42e3-8fd1-0f374b908432%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/1415422897.2447.0%40smtp.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to