Bug #11912

Ruby DSL should be able to use defined resources

Added by Hunter Haugen 4 months ago. Updated about 1 month ago.

Status:Accepted Start date:01/12/2012
Priority:Normal Due date:
Assignee:- % Done:

0%

Category:language
Target version:3.X
Affected Puppet version: Branch:
Keywords:rubydsl, ruby, dsl, define
Votes: 2

Description

Currently there is no way to use defined resources in puppet ruby dsl. At all.

Given a module called test with two defined resources:

1st: test/manifests/def.pp

define test::def {
  notify { 'test':
    message => "Some test def for $name",
  }
}

2nd: test/manifests/ruby_def.rb

define 'test::ruby_def' do
  notify 'ruby test',
    :message => "Some ruby test def for $name"
end

I can use both of these from a normal puppet manifest just fine:

test/manifests/include.pp

class test::include {
  test::def { 'my title1': }
  test::ruby_def { 'my ruby title1': }
}

THE BUG: The following example does not work. Puppet Ruby DSL cannot use either ruby defines or puppet defines with create_resource, and there are no other alternatives to use them. So defined resources are not possible to use in the puppet ruby dsl afaict:

test/manifests/ruby_include.pp

hostclass 'test::ruby_include' do
  create_resource 'test::def', 'my title'
  create_resource 'test::ruby_def', 'my ruby title'
end

The errors given:

Cannot find definition Test::Def on node training.puppetlabs.lan
Cannot find definition Test::Ruby_def on node training.puppetlabs.lan

Related issues

duplicated by Puppet - Bug #13101: Ruby DSL can not auto import file that only contains defi... Duplicate 03/13/2012

History

Updated by Hunter Haugen 4 months ago

  • Description updated (diff)

Updated by Daniel Pittman 4 months ago

  • Status changed from Unreviewed to Accepted
  • Target version set to 3.X

Updated by Daniel Pittman 4 months ago

This is actually on the platform road-map for Telly, so we expect to get it fixed. Patches, obviously, happily accepted.

Updated by Dominic Cleal 4 months ago

  • Category set to language

Updated by Matthew Leather 4 months ago

I’m using this as a workaround, it seems to be working.

scope.find_resource_type 'test::def'
create_resource 'test::def'

Updated by Simon Effenberg about 1 month ago

the trick with

scope.find_resource_type 'test::def'

works for me.. but it is not always necessary so the following didn’t worked:

create_resource 'munin::plugin::config', munin_plugin_name, :content => 'xxx'
create_resource 'munin::plugin', munin_plugin_name, :ensure => 'present', :source_name => 'solr_'

but these both worked:

create_resource 'munin::plugin', munin_plugin_name, :ensure => 'present', :source_name => 'solr_'

or

scope.find_resource_type 'munin::plugin::config'
create_resource 'munin::plugin::config', munin_plugin_name, :content => 'xxx'
create_resource 'munin::plugin', munin_plugin_name, :ensure => 'present', :source_name => 'solr_'

Also available in: Atom PDF