Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to use the Puppet server as a variable in my puppet template like this: <%= $settings::server %>. But I get an error:

undefined method `server' for nil:NilClass

How can I use the configured Puppet server as a variable in my templates?

share|improve this question
up vote 3 down vote accepted

You're trying to use Puppet syntax variable lookups in ERB, and that won't work. ERB is not Puppet, and the two syntaxes are not compatible. Instead, you want to assign the value to a simple (non-namespaced) variable in your manifest, and then use that variable in your ERB. You can use scope, as kashani suggests, but nobody else (or you in 6 months) will know WTF you're doing and why it's important.

share|improve this answer
I'm not a fan creating local variables when you have scoped ones which indicate origin, but to each their own. :-) Admittedly I think settings classes are far more trouble than they are worth and a poor substitute for Hiera or other external data lookup. – kashani Jul 10 '12 at 21:09
Puppet scoping is insane, and they're in the process of reworking it for the next version, which will make everything change again. Local variables and composition are the only sane way to do Puppet manifests. – womble Jul 10 '12 at 21:28
Thanks, after working with Puppet more, I understand what is happening now and why this answer is a little more safer down the road. – Andy Shinn Sep 24 '12 at 21:22

Try the following. It's a bit wordier, but should be the most reliable. FWIW, removing the $ should also work, but might not after Puppet 2.7.

<%= scope.lookupvar('settings::server') %>
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.