Hi, I''ve got a problem when using templates in Puppet. In my node declarations, i set (or not) some special variables to activate (or not) some part of my configuration. When i don''t need the configuration part, i don''t declare the variable. I then use something like this in my templates: ... <% if defined? myvar %> ... myvalue = <%= myvar %> ... <% end %> ... The problem is that it doesnt work with Puppet. If i don''t declare "myvar" in my node, the "if" part is not taken into account (this is the right behaviour). Buf if i try to use a "myvar" in my node, the "if" part is still not taken into account. If i use the "erb" command on my template to test it, all is ok (i just added a "<% myvar = "My value" %>" line at the beginning of the template). I''m not a specialist of Ruby so i guess i do some mistakes in the template... Any idea about this problem?
2007/2/14, Sébastien Prud''homme <sebastien.prudhomme@gmail.com>:> > Hi, > > I''ve got a problem when using templates in Puppet. > > In my node declarations, i set (or not) some special variables to > activate (or not) some part of my configuration. When i don''t need the > configuration part, i don''t declare the variable. > > I then use something like this in my templates: > > ... > <% if defined? myvar %> > ... > myvalue = <%= myvar %> > ... > <% end %> > ... > > The problem is that it doesnt work with Puppet. If i don''t declare > "myvar" in my node, the "if" part is not taken into account (this is > the right behaviour). Buf if i try to use a "myvar" in my node, the > "if" part is still not taken into account. > > If i use the "erb" command on my template to test it, all is ok (i > just added a "<% myvar = "My value" %>" line at the beginning of the > template). > > I''m not a specialist of Ruby so i guess i do some mistakes in the > template... > > Any idea about this problem? >Have you tried using if( myvar ) ? Best regards Jose _______________________________________________ Puppet-users mailing list Puppet-users@madstop.com https://mail.madstop.com/mailman/listinfo/puppet-users
On Feb 14, 2007, at 8:10 AM, Sébastien Prud''homme wrote:> Hi, > > I''ve got a problem when using templates in Puppet. > > In my node declarations, i set (or not) some special variables to > activate (or not) some part of my configuration. When i don''t need the > configuration part, i don''t declare the variable. > > I then use something like this in my templates: > > ... > <% if defined? myvar %> > ... > myvalue = <%= myvar %> > ... > <% end %>Template support in Puppet uses a bit of a Ruby hack and doesn''t create real variables. As José said, use ''if myvar'', because that will use the the method_missing system that I''m taking advantage of. Basically, Ruby treats unqualified variables and methods equivalently, so I catch the method_missing errors, look up variables with those names, and return them if I have them. An exception *might* get thrown here if the variable is not defined, I can''t remember; I implemented it one way, and then changed it when someone complained, but I can''t remember which is which at this point. -- Always behave like a duck - keep calm and unruffled on the surface but paddle like the devil underneath. -- Jacob Braude --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com