Issue #16688 has been updated by Avishai Ish-Shalom.
The above patch doesn't work for puppet 3.x. For puppet 3.x the calling_class
lookup should use the following snippet:
<pre><code class="ruby>
def [](key)
if key == "calling_class"
def recurse_for_hostclass(scope)
if scope.source.type == :hostclass
return scope.source.name
elsif scope.parent
return recurse_for_hostclass(scope.parent)
else
return nil
end
end
ans = recurse_for_hostclass(@real)
elsif key == "calling_module"
</code></pre>
----------------------------------------
Bug #16688: scope.function_hiera looks up wrong calling_module and
calling_class when template is used inside definition
https://projects.puppetlabs.com/issues/16688#change-72319
Author: Avishai Ish-Shalom
Status: Unreviewed
Priority: Normal
Assignee:
Category:
Target version:
Affected Puppet version: 3.0.0
Keywords:
Branch:
Same as Hiera issue #16555, i'm re-opening as a puppet 3.x issue since hiera
has been integrated.
<pre><code>
class test {
file{"/tmp/test":
content => template("test/test.erb"),
mode => 644
}
define test::test_file {
file {"/tmp/$name":
mode => 644,
content => template("test/test.erb"),
}
}
test::test_file {"test-definition": }
}
</code></pre>
template:
<pre><code>
<%= scope.function_hiera(["test", "%{calling_module}"]) %>
</code></pre>
Test file will show the definition type name instead of the calling module
name. this is due to hiera/scope.rb using scope.resource.name.split(“::”) which
is incorrect for defined types. This patch does the trick:
<pre>
--- a/lib/hiera/scope.rb
+++ b/lib/hiera/scope.rb
@@ -8,9 +8,9 @@ class Hiera
def [](key)
if key == "calling_class"
- ans = @real.resource.name.to_s.downcase
+ ans = @real.scope_path.find {|c| c.source.type == :hostclass
}.source.name
elsif key == "calling_module"
- ans = @real.resource.name.to_s.downcase.split("::").first
+ ans = @real.source.module_name
else
ans = @real.lookupvar(key)
end
@@ -38,4 +38,4 @@ class Hiera
</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.