Issue #15448 has been updated by eric sorenson.

The cleanest way to do this is to use the instance variable form, `@foo` -- 
this works correctly in 2.6, 2.7, and 3.0:

<pre>

<% if @foo %>foo <%= scope.lookupvar('foo') -%><% else %>not foo<% end %>

</pre>

outputs 'not foo' for all versions.  

http://docs.puppetlabs.com/guides/templating.html#testing-for-undefined-variables
----------------------------------------
Bug #15448: scope.lookupvar('any variable') is always TRUE.
https://projects.puppetlabs.com/issues/15448#change-73997

Author: Jos Boumans
Status: Duplicate
Priority: Normal
Assignee: 
Category: 
Target version: 
Affected Puppet version: 2.6.16
Keywords: undef
Branch: 


Even when such a variable doesn't exist or hasn't been defined. 

Consider the following script:

<pre>
$ cat z.pp
$x = inline_template( "<% if scope.lookupvar('foo') %>foo <%= 
scope.lookupvar('foo') -%><% end %>" )
$y = inline_template( "<% if scope.lookupvar('foo').length > 0 %>foo <%= 
scope.lookupvar('foo') -%><% end %>" )
notice( "x: $x" )
notice( "y: $y" )
</pre>

I'd expect both notices to NOT print out "foo". However, the "x:" line does:

<pre>
$ sudo puppet z.pp
notice: Scope(Class[main]): x: foo 
notice: Scope(Class[main]): y: 
</pre>

If the scope.lookupvar is omitted, and just <% if foo %> is used, this throws a 
puppet error,
which is not desired, but much more along the lines of expectation.

<pre>
Failed to parse inline template: Could not find value for 'foo' at z.pp:1 on 
node ...
</pre> 


-- 
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-bugs?hl=en.

Reply via email to