On Apr 15, 2:10 pm, Clay Caviness <ccavin...@gmail.com> wrote:
> Let's say I have a very simple template
> template.erb:
> <% if not has_variable?("foobar") then foobar = "undefined" end -%>
> foobar: <%= foobar %>
> class: <%= foobar.class %>
>
> And a basic manifest:
> template.pp:
> $mytemp = template('template.erb')
> notice($mytemp)
>
> And then I apply the manifest, with an undefined foobar (no foobar fact):
> $ puppet apply ~/template.pp
> notice: Scope(Class[main]): foobar: undefined
> class: String
>
> notice: Finished catalog run in 0.01 seconds
>
> Looking good. So now I apply the manifest, but with a defined value
> for foobar (via the FACTER_FOOBAR environment variable):
> $ FACTER_FOOBAR='foo' puppet apply ~/template.pp
> notice: Scope(Class[main]): foobar:
> class: NilClass
>
> notice: Finished catalog run in 0.01 seconds
>
> Er, what? How on earth did foobar go from a String to NilClass? I
> can't fathom how this is expected, or correct...

It looks like the variable is defined, and has the (Ruby) value nil.
This could be because the variable was previously assigned a (possibly
different) value when a different catalog was compiled, but not
assigned a value for the current catalog.  And THAT might be because
Ruby and shell variable names are both case-sensitive.  Does it work
better if you write

    FACTER_foobar='foo' puppet apply ~/template.pp

?

>
> The reason I was doing this sort of thing is to give a possibly
> missing fact a default value. I ended up using a second variable, like
> this:
> <% foo = has_variable?("foobar") ? foobar.to_s : "false" -%>


If I have analyzed the problem correctly, then you should also be able
to do it this way:

<% if not has_variable?("foobar") or foobar.nil then foobar =
"undefined" end -%>


John

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to