PSA regarding Puppet template variables and default values

Inside of a Puppet template, you would think that one of these would work to set a default value for something not explicitly defined in your manifest:

It doesn’t. This will clobber the variable, every time.

To understand why this happens, you need to consider two critical pieces of information:

  1. The architecture of Puppet is stupidly complicated, which leads to unexpected behaviors all over the place.
  2. Because Puppet variables are lazy-loaded, they need to reinvent how variables are accessed in the ERb templating system. The Puppet developers, in their infinite wisdom, decided to do this by using method_missing and dumping leaky abstractions all over the place.

To summarize, the reason this doesn’t work is because there really isn’t a variable named my_var at all. ERb tries to find a symbol called my_var and can’t, because that thing that looks like a variable is really syntactic sugar over something completely different happening under the covers.

The correct way to do this is to force a lookup through the scope object as follows:

The more vested I get in Puppet, the more I want to try out Chef.


  1. I initially started out with Chef. The documentation is a pain to get through, but once you get it, you will flow. Puppets files are almost the same as Chef’s.

    These systems can only get better of course, but both feel like hacks.

  2. You share interesting things here. I think that your website can go viral easily,
    but you must give it initial boost and i know how to do it, just type in google
    for – wcnu traffic increase

  3. Your blog is STELLAR! I mean, Ive never been so entertained by anything in my life! Your vids are perfect for this. I mean, how did you manage to find something that matches your style of writing so well? Im really happy I started reading this today. Youve got a follower in me for sure!

  4. I have noticed you don’t monetize your site, don’t waste your traffic, you
    can earn additional cash every month because you’ve got
    hi quality content. If you want to know how to make extra money, search
    for: Mrdalekjd methods for $$$

Leave a Reply

Your email address will not be published.

© 2019 @jgoldschrafe

Theme by Anders NorenUp ↑