Writings on various topics (mostly technical) from Oliver Hookins and Angela Collins. We currently reside in Sydney after almost a decade in Berlin, have three kids, and have far too little time to really justify having a blog.
that if you pass a Ruby symbol through the Puppet external node classifier interface, through a parametrised class and into an ERB template, it will arrive (relatively) unscathed? OK not really, but the special undef Puppet symbol does.
ENC says: myvariable: :undef
Puppet interprets it as a standard undef (which is internally represented as Puppet::Parser::AST::Undef).
When passed through to an ERB template, it again arrives as the symbol form :undef, which means you can do things like
<% if proxy_host != :undef -%>
proxyhost=<%= proxy_host %>
proxyport=<%= proxy_port %>
<% end -%>
This does bring up an interesting conundrum about variable usage in templates. When you are faced with the pattern of "check some variable, and if the condition is true, enable a whole block of text which involves substitution", what is the best way to express it? There are a few options:
One of my gripes with the Puppet DSL (and let's face it, who doesn't have at least one) is that the type system is inherently different to Ruby's. While there is the undef "value", it doesn't behave like the Ruby nil. Empty strings evaluate as false in Puppet; in Ruby they evaluate as true. It is not permissible to pass undef to a class or definition that wasn't already set up with a default value. This clearly contrasts with Ruby where nil is a perfectly permissible value to supply (and evaluates as false).
My problems with the above patterns are as follows:
<%= proxy_enabler : 'true' ? 'false' %> but this seems even more
confusing, even if you understand the ternary operator.This shows just some of the madness I have to endure day to day. I'd love to know your thoughts on this, as I still haven't really made my mind up. I did actually request nil to be added to the Puppet language but my ideas on how best this can be applied is still floating about in the wind.