Issue #8707 has been updated by Steve Shipway.
Affected Puppet version changed from 2.7.1 to 2.7.10
Please fix this; I've lost just over an hour trying to work out why
lookupvar("foo").to_i is returning 55758 (turns out this is the value of
:undefined).
We have 2.7.10 and the problem is still present.
----------------------------------------
Bug #8707: Scope.lookupvar() returns undef perhaps should return nil
https://projects.puppetlabs.com/issues/8707#change-61040
Author: Karl Pietri
Status: Accepted
Priority: Normal
Assignee:
Category: templates
Target version: 2.7.x
Affected Puppet version: 2.7.10
Keywords:
Branch:
When in a erb template in puppet if you use scope.lookupvar() with a variable
that doesn't exist you get a return value of the label undefined (:undefined)
this breaks being able to do this:
<% if scope.lookupvar("::ipadress_eth2") %>i have an eth2 <% end %>
Examples:
err(inline_template('testing truth: <% if
scope.lookupvar("::ipaddress_eth1") %>has ip: <%=
scope.lookupvar("::ipaddress_eth1") %><% else %>has no ip<% end %>'))
err(inline_template('testing undefined str: <% if
scope.lookupvar("::ipaddress_eth1")!="undefined" %>has ip: <%=
scope.lookupvar("::ipaddress_eth1") %><% else %>has no ip<% end %>'))
err(inline_template('testing undefined label: <% if
scope.lookupvar("::ipaddress_eth1")!=:undefined %>has ip: <%=
scope.lookupvar("::ipaddress_eth1") %><% else %>has no ip<% end %>'))
output:
Jul 29 12:10:29 monitor1.example.com puppet-master[533]:
(Scope(Class[Shared::Sshd])) testing truth: has ip: undefined
Jul 29 12:10:29 monitor1.example.com puppet-master[533]:
(Scope(Class[Shared::Sshd])) testing undefined str: has ip: undefined
Jul 29 12:10:29 monitor1.example.com puppet-master[533]:
(Scope(Class[Shared::Sshd])) testing undefined label: has no ip
Perhaps the function should return nil instead of :undefined to prevent
confusion
-karl
PS not sure if this is a bug or a feature request
--
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.