5

Is it possible to access Puppet master configuration variables (like confdir, masterport, etc) from within a Puppet manifest?

6
  • not as far as i know. what are you trying to do?
    – rytis
    Jan 27, 2010 at 17:15
  • I do a lot of custom plugins, so instead of using environments I am running two separate daemons for Production and Testing. Some of my plugins (including my external nodes script) need to reference external config files whose locations change based on the daemon I'm in. I'd like to be able to set a variable in my puppet.conf and then reference it from my manifests instead of having to change the locations on every pull/merge from testing to production.
    – sh-beta
    Jan 28, 2010 at 15:22
  • i see now. have you thought of running production and test daemons in chroot'ed environment, so you can use same paths in both environments? lets say /etc/test/puppet and /etc/prod/puppet, and when you start youd chroot first to either /etc/test or /etc/prod ? just like bind does? and then within that env paths are the same
    – rytis
    Jan 28, 2010 at 20:42
  • That would work for this particular example but other things like the puppet-client module, which requires the puppetmaster name and port number, are still problematic.
    – sh-beta
    Feb 3, 2010 at 18:11
  • Marking this as my answer since it doesn't appear to be possible.
    – sh-beta
    Mar 15, 2010 at 14:24

1 Answer 1

8

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .