Friday, November 16, 2012

Writing custom functions in puppet

WARNING: The content of the post is changed.  It was originally written with a different intent.

I'll  go about creating a custom function that'll send a string passed to it to the relevant debug level.
Puppet::Parser::Functions::newfunction(:debug_msg, :type => :statement, :doc => "
Send messages to a particular debug level
") do |vals|
  $level, $debug_message = vals
  $possible_levels = ["debug","info","notice","warning","err","alert","emerg","crit"]
  if $possible_levels.include? $level
    raise(ArgumentError, 'Must specify proper debug type. It can be either "debug","info","notice","warning","err","alert","emerg" or "crit" ')
  Puppet.send($level.to_sym, $debug_message)

And then in your manifest, you can do simply like:
debug_msg("notice","NOTICE message")
debug_msg("debug", "Send as a debug message")
The above statement debug_msg("notice","NOTICE message") is exactly similar to:
notice("NOTICE message") 
You'll have to place this function as a ".rb" file under the  lib/puppet/parser/functions/ directory of any relevant module
That's about it for this quick post.

1 comment:

  1. GSCopy
    Pro v6.0 (RoboCopy Alternative) with Open File Agent

    GSCopyPro is a single command-line
    tool (CLI) that can copy, replicate and move files from one folder to another.
    This folder can be on the same machine/ server or another server elsewhere.
    What makes GSCopyPro stand out from other competitors is the
    fact it works on 32-bit as well as 64-bit systems and has no restrictions. It can easily be scheduled to run as a scheduled task
    and fully automated. GSCopyPro also comes with an open file agent which can
    copy files that are locked/ opened by other processes. This feature is
    supported in all windows vSCersions from widows XP/ 2003 and later.

    Go To:>>