Issue #5236 has been updated by Kristian Kostecky.
Here's a workaround that allows you to build a parameterized class in the ruby
DSL. The idea is to build a wrapper class in the puppet DSL that accepts
parameters. You then suck in the parameters in to a local variable of the
wrapper class so that you can explicitly reference it in the ruby DSL. Next,
include the class you've written in the ruby DSL. This class written in the
Ruby DSL will then use scope.lookupvar() to pull in the parameters you need.
The following example contains a simple string, but this works for hashes,
arrays, strings and any combination.
test_wrapper.pp:
class test_class::test_wrapper ($keys = {}) {
$wrap_keys = $keys
include test_class::test_class
}
test_class.rb:
hostclass "test_class::test_class" do
keys = scope.lookupvar('test_class::test_wrapper::wrap_keys')
notify "DEBUG", :message => "DEBUG: #{keys}"
end
In your node def:
node "test_node" {
class { "test_class::test_wrapper": keys => "TESTING" }
}
----------------------------------------
Bug #5236: Ruby DSL cannot declare parameterized classes
https://projects.puppetlabs.com/issues/5236
Author: Dan Bode
Status: Accepted
Priority: High
Assignee:
Category: API
Target version:
Affected Puppet version:
Keywords: internal dsl hostclass
parameterized_classes
Branch:
it should be possible to declare parameterized classes using the ruby dsl:
/tmp/notify.rb
<pre>
hostclass 'foo', 'bar' do
notify 'foop', :message => 'foobar'
end
node 'default' do
hostclass 'foo', :bar => 'test'
end
</pre>
trying to apply the above manifest, results in the error below.
<pre>
#>puppet apply /tmp/notify.rb --debug --trace
/usr/lib/ruby/site_ruby/1.8/puppet/dsl/resource_api.rb:38:in `method_missing'
(eval):7:in `parse_ruby_file'
/usr/lib/ruby/site_ruby/1.8/puppet/dsl/resource_api.rb:19:in `instance_eval'
/usr/lib/ruby/site_ruby/1.8/puppet/dsl/resource_api.rb:19:in `evaluate'
/usr/lib/ruby/site_ruby/1.8/puppet/resource/type.rb:295:in `evaluate_ruby_code'
/usr/lib/ruby/site_ruby/1.8/puppet/resource/type.rb:78:in `evaluate_code'
/usr/lib/ruby/site_ruby/1.8/puppet/parser/resource.rb:71:in `evaluate'
/usr/lib/ruby/site_ruby/1.8/puppet/parser/compiler.rb:225:in `evaluate_ast_node'
/usr/lib/ruby/site_ruby/1.8/puppet/parser/compiler.rb:103:in `compile'
/usr/lib/ruby/site_ruby/1.8/puppet/parser/compiler.rb:18:in `compile'
/usr/lib/ruby/site_ruby/1.8/puppet/indirector/catalog/compiler.rb:77:in
`compile'
/usr/lib/ruby/site_ruby/1.8/puppet/util.rb:188:in `benchmark'
/usr/lib/ruby/site_ruby/1.8/puppet/indirector/catalog/compiler.rb:75:in
`compile'
/usr/lib/ruby/site_ruby/1.8/puppet/indirector/catalog/compiler.rb:34:in `find'
/usr/lib/ruby/site_ruby/1.8/puppet/indirector/indirection.rb:193:in `find'
/usr/lib/ruby/site_ruby/1.8/puppet/indirector.rb:50:in `find'
/usr/lib/ruby/site_ruby/1.8/puppet/application/apply.rb:115:in `main'
/usr/lib/ruby/site_ruby/1.8/puppet/application/apply.rb:35:in `run_command'
/usr/lib/ruby/site_ruby/1.8/puppet/application.rb:287:in `run'
/usr/lib/ruby/site_ruby/1.8/puppet/application.rb:393:in `exit_on_fail'
/usr/lib/ruby/site_ruby/1.8/puppet/application.rb:287:in `run'
/usr/lib/ruby/site_ruby/1.8/puppet/util/command_line.rb:55:in `execute'
/usr/bin/puppet:4
/usr/lib/ruby/site_ruby/1.8/puppet/parser/compiler.rb:21:in `compile'
/usr/lib/ruby/site_ruby/1.8/puppet/indirector/catalog/compiler.rb:77:in
`compile'
/usr/lib/ruby/site_ruby/1.8/puppet/util.rb:188:in `benchmark'
/usr/lib/ruby/site_ruby/1.8/puppet/indirector/catalog/compiler.rb:75:in
`compile'
/usr/lib/ruby/site_ruby/1.8/puppet/indirector/catalog/compiler.rb:34:in `find'
/usr/lib/ruby/site_ruby/1.8/puppet/indirector/indirection.rb:193:in `find'
/usr/lib/ruby/site_ruby/1.8/puppet/indirector.rb:50:in `find'
/usr/lib/ruby/site_ruby/1.8/puppet/application/apply.rb:115:in `main'
/usr/lib/ruby/site_ruby/1.8/puppet/application/apply.rb:35:in `run_command'
/usr/lib/ruby/site_ruby/1.8/puppet/application.rb:287:in `run'
/usr/lib/ruby/site_ruby/1.8/puppet/application.rb:393:in `exit_on_fail'
/usr/lib/ruby/site_ruby/1.8/puppet/application.rb:287:in `run'
/usr/lib/ruby/site_ruby/1.8/puppet/util/command_line.rb:55:in `execute'
/usr/bin/puppet:4
undefined method `hostclass' for #<Puppet::DSL::ResourceAPI:0xb790786c> on node
puppetfoo.localdomain
</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.