Issue #22121 has been updated by Thomas Vander Stichele.
If @variable.nil? works, then that's great! Did you notice that this section of the documentation is a) very long and b) *does not contain the solution written out* ? It's great that it tells you you should test for nil, but it doesn't say how that's done. The short version should simply say: "When testing for undefinedness, use '@variable.nil?' to check whether the instance ..." A whole page of text, but the solution isn't actually on there. Suggest changing the docs then. ---------------------------------------- Bug #22121: Documentation about testing for existence of variable in template is subtly wrong https://projects.puppetlabs.com/issues/22121#change-98322 * Author: Thomas Vander Stichele * Status: Closed * Priority: Normal * Assignee: Yoann Le Touche * Category: documentation * Target version: * Affected Puppet version: * Keywords: template, test, variable * Branch: ---------------------------------------- http://docs.puppetlabs.com/guides/templating.html If the variable is defined but false, if @variable is false just the same. So using @ cannot be used purely to test definedness. In my template, I worked around it like this: <% if @require_valid_user == false -%> require_valid_user = false <% elsif @require_valid_user == true -%> require_valid_user = true <% else -%> ; require_valid_user = false <% end -%> I suggest updating the docs at least, or providing a real way to test for definedness-but-nothing-else. -- You have received this notification because you have either subscribed to it, or are involved in it. To change your notification preferences, please click here: http://projects.puppetlabs.com/my/account -- You received this message because you are subscribed to the Google Groups "Puppet Bugs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/puppet-bugs. For more options, visit https://groups.google.com/groups/opt_out.
