Accessing puppet configuration variables from manifests?

There are three ways.

  1. Jeff McCune has a nice function on his github that does exactly this:
    module Puppet::Parser::Functions
      newfunction(:getconf, :type => :rvalue, :doc => 
    2010-09-29

    The getconf function takes a single argument, the name of a
    configuration setting and returns the value of that setting.

    It is similar to the --configprint command line argument to
    return configuration settings except it exposes this information
    to the language.
    END_HEREDOC
      do |args|
        if args.length != 1 then
          raise Puppet::ParseError, ("ERROR: getconf() takes only one argument")
        end
        Puppet[args[0]]
      end # do |args|
    end # module
    # EOF

Put this in a file called 'getconf.rb' in your puppet server's libdir (/var/puppet/lib/puppet/parser/functions/getconf.rb) and access it from a manifest like

# somemanifest.pp
$myvar = getconf("ssldir")
notify {"set ssldir to ${myvar}":}

2. In Puppet 2.6 it's even easier as the whole settings setup is accessible as ${settings::somevar}, so the manifest is simply:

# 26manifest.pp
$myvar = $settings::ssldir
notify {"set ssldir to $myvar":}

3. In puppet 0.25 you can use an inline template:

# 25manifest.pp 
$myvar = inline_template("<%= Puppet.settings[:ssldir] %>")
notify {"set ssldir to ${myvar}":}

Methods 2 and 3 thanks to this thread on puppet-users