piavlo
2011-Aug-11 16:06 UTC
[Puppet Users] need urgent help with including Ruby DSL class from puppet manifests
Hi, I have a Ruby class in "nagios" module - it''s located in nagios/ manifests/ssa_nagios_checks.rb and looks like this hostclass :ssa_nagios_checks do ... end In nagios/manifests/init.pp I have class nagios::server { ... include ssa_nagios_checks ... } And I get the following error .... debug: importing ''/etc/puppet/modules/nagios/manifests/ ssa_nagios_checks.rb'' in environment production err: Must pass a parameter or all necessary values at /etc/puppet/ modules/nagios/manifests/init.pp:19 on node mon1a.internal I could not find nothing on the web regarding this specific error message. What does it actualy means? Then I change to class nagios::server { ... include nagios::ssa_nagios_checks ... } I get error ... debug: importing ''/etc/puppet/modules/nagios/manifests/ ssa_nagios_checks.rb'' in environment production err: Could not find class nagios::ssa_nagios_checks for mon1a.internal at /etc/puppet/modules/nagios/manifests/init.pp:20 on node mon1a.internal Also instead I tried to use ssa_nagios_checks.rb from another module I have another puppet class in "ssa" module located at ssa/manifests/nagios.pp which has class ssa::nagios { ... include ssa_nagios_checks ... } And I''m getting the following error: err: Could not find class ssa_nagios_checks for mon1a.internal at /etc/ puppet/modules/ssa/manifests/nagios.pp:5 on node mon1a.internal Then I change to class ssa::nagios { ... include nagios::ssa_nagios_checks ... } Since ssa_nagios_checks is under "nagios" module - and still I get: err: Could not find class nagios::ssa_nagios_checks for mon1a.internal at /etc/puppet/modules/ssa/manifests/nagios.pp:5 on node mon1a.internal I have no ideas how to solve these 2 problems - which are - how do I properly use Ruby DSL class in the same module and how do I use it in another module? Thanks Alex -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Stefan Schulte
2011-Aug-11 18:02 UTC
Re: [Puppet Users] need urgent help with including Ruby DSL class from puppet manifests
On Thu, Aug 11, 2011 at 09:06:37AM -0700, piavlo wrote:> Hi, > > I have a Ruby class in "nagios" module - it''s located in nagios/ > manifests/ssa_nagios_checks.rb > and looks like this > > hostclass :ssa_nagios_checks do > ... > end > > In nagios/manifests/init.pp I have > > class nagios::server { > ... > include ssa_nagios_checks > ... > } >I may be wrong here but I guess you cannot mix manifests written in ruby DSL with classes written in pure puppet DSL. -Stefan
Ken Barber
2011-Aug-11 18:13 UTC
Re: [Puppet Users] need urgent help with including Ruby DSL class from puppet manifests
If you look at this example:>> I have a Ruby class in "nagios" module - it''s located in nagios/ >> manifests/ssa_nagios_checks.rb >> and looks like this >> >> hostclass :ssa_nagios_checks do >> ... >> end >> >> In nagios/manifests/init.pp I have >> >> class nagios::server { >> ... >> include ssa_nagios_checks >> ... >> }The autoloader/module layout recommendations/rules haven''t been followed. You actually want something more like: nagios/manifests/server.pp: class nagios::server { include nagios::ssa_nagios_checks } nagios/manifests/ssa_nagios_checks.rb: hostclass :''nagios::ssa_nagios_checks'' do notice(["should work"]) end This should work. Can you test it? Remember that sub-classes belong in their own file ... and only the class with the same name as the module belongs in init.pp. Also - you have to fully qualify class names when declaring them in their rb/pp file. ken. -- "Join us for PuppetConf, September 22nd and 23rd in Portland, OR: http://bit.ly/puppetconfsig" -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
piavlo
2011-Aug-11 20:34 UTC
[Puppet Users] Re: need urgent help with including Ruby DSL class from puppet manifests
Hi Ken, Thank you so much for your reply I did like you said BUT i was still getting the error err: Must pass a parameter or all necessary values at /etc/puppet/ modules/nagios/manifests/server.pp:19 on node mon1a.internal Then I started to insert notice statement in the ruby DSL class - it turns out I a logical erro in the code. Arghhh - I have been so fooled by the totally misguiding error message. Shouldn''t puppet err indicate that there is problem in /etc/puppet/ modules/nagios/manifests/ssa_nagios_checks.rb and not in /etc/puppet/ modules/nagios/manifests/server.pp? Anyway now that the ruby error is fixed I get new error err: undefined method `Puppet'' for #<Puppet::DSL::ResourceAPI: 0xb73f50e0> at /etc/puppet/modules/nagios/manifests/server.pp:15 on node mon1a.internal What does this error means? Here is the real ruby dsl class code - in case it''s again a problem with the class :) ---------------- require ''json'' require ''open-uri'' hostclass :''nagios::ssa_nagios_checks'' do nagios_confdir = scope.lookupvar(''nagios::params::nrpe_confdir'') url = "http://localhost:5984/nagios_alerts/_all_docs? include_docs=true" result = JSON.parse(open(URI.parse(url)).read) result[''rows''].each do |x| type = x[''doc''][''type''] args = x[''doc''][''args''] warning_threshold = x[''doc''][''warning_threshold''] critical_threshold = x[''doc''][''critical_threshold''] contacts = x[''doc''][''contacts''] contact_groups = x[''doc''][''contact_groups''] notification_period = x[''doc''][''notifications_period''] case type when "mysql" mysql_user = ''nagios'' mysql_password = ''xxxx'' check_command = "check_mysql_health_sql_tresholds!#{mysql_user}! #{mysql_password}!''#{args}''!#{warning_threshold}! #{critical_threshold}" when "api" check_command = "blah-blah" else raise Puppet:Error, "Unsupported ssa nagios check type $type" end nagios_service( "ssa_#{x[''doc''][''_id'']}", :target => "${nagios_confdir}/app_alerts/ssa/ services/${name}.cfg", :host_name => x[''doc''][''hosts''], :service_description => x[''doc''][''desc''], :use => ''generic-service'', :check_command => check_command, :require => "File[#{nagios_confdir}/app_alerts/ssa/ services]" ) end end ---------------- Thanks Alex On Aug 11, 9:13 pm, Ken Barber <k...@puppetlabs.com> wrote:> If you look at this example: > > >> I have a Ruby class in "nagios" module - it''s located in nagios/ > >> manifests/ssa_nagios_checks.rb > >> and looks like this > > >> hostclass :ssa_nagios_checks do > >> ... > >> end > > >> In nagios/manifests/init.pp I have > > >> class nagios::server { > >> ... > >> include ssa_nagios_checks > >> ... > >> } > > The autoloader/module layout recommendations/rules haven''t been followed. > > You actually want something more like: > > nagios/manifests/server.pp: > > class nagios::server { > include nagios::ssa_nagios_checks > } > > nagios/manifests/ssa_nagios_checks.rb: > > hostclass :''nagios::ssa_nagios_checks'' do > notice(["should work"]) > end > > This should work. Can you test it? > > Remember that sub-classes belong in their own file ... and only the > class with the same name as the module belongs in init.pp. Also - you > have to fully qualify class names when declaring them in their rb/pp > file. > > ken. > > -- > "Join us for PuppetConf, September 22nd and 23rd in Portland, OR:http://bit.ly/puppetconfsig"-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Ken Barber
2011-Aug-11 21:17 UTC
Re: [Puppet Users] Re: need urgent help with including Ruby DSL class from puppet manifests
Is it this line? raise Puppet:Error, "Unsupported ssa nagios check type $type" Should be double colon ... Puppet::Error. Looking at your code, I can''t help but think a function is a better fit then Ruby DSL. ken. On Thu, Aug 11, 2011 at 9:34 PM, piavlo <lolitushka@gmail.com> wrote:> Hi Ken, > > Thank you so much for your reply > I did like you said BUT i was still getting the error > > err: Must pass a parameter or all necessary values at /etc/puppet/ > modules/nagios/manifests/server.pp:19 on node mon1a.internal > > Then I started to insert notice statement in the ruby DSL class - it > turns out I a logical erro in the code. > Arghhh - I have been so fooled by the totally misguiding error > message. > Shouldn''t puppet err indicate that there is problem in /etc/puppet/ > modules/nagios/manifests/ssa_nagios_checks.rb and not in /etc/puppet/ > modules/nagios/manifests/server.pp? > > Anyway now that the ruby error is fixed I get new error > err: undefined method `Puppet'' for #<Puppet::DSL::ResourceAPI: > 0xb73f50e0> at /etc/puppet/modules/nagios/manifests/server.pp:15 on > node mon1a.internal > > What does this error means? > > Here is the real ruby dsl class code - in case it''s again a problem > with the class :) > > ---------------- > require ''json'' > require ''open-uri'' > > hostclass :''nagios::ssa_nagios_checks'' do > > nagios_confdir = scope.lookupvar(''nagios::params::nrpe_confdir'') > > url = "http://localhost:5984/nagios_alerts/_all_docs? > include_docs=true" > result = JSON.parse(open(URI.parse(url)).read) > > result[''rows''].each do |x| > > type = x[''doc''][''type''] > args = x[''doc''][''args''] > warning_threshold = x[''doc''][''warning_threshold''] > critical_threshold = x[''doc''][''critical_threshold''] > > contacts = x[''doc''][''contacts''] > contact_groups = x[''doc''][''contact_groups''] > notification_period = x[''doc''][''notifications_period''] > > case type > when "mysql" > mysql_user = ''nagios'' > mysql_password = ''xxxx'' > check_command = "check_mysql_health_sql_tresholds!#{mysql_user}! > #{mysql_password}!''#{args}''!#{warning_threshold}! > #{critical_threshold}" > when "api" > check_command = "blah-blah" > else > raise Puppet:Error, "Unsupported ssa nagios check type $type" > end > > nagios_service( "ssa_#{x[''doc''][''_id'']}", > :target => "${nagios_confdir}/app_alerts/ssa/ > services/${name}.cfg", > :host_name => x[''doc''][''hosts''], > :service_description => x[''doc''][''desc''], > :use => ''generic-service'', > :check_command => check_command, > :require => "File[#{nagios_confdir}/app_alerts/ssa/ > services]" ) > > end > > end > ---------------- > > Thanks > Alex > > On Aug 11, 9:13 pm, Ken Barber <k...@puppetlabs.com> wrote: >> If you look at this example: >> >> >> I have a Ruby class in "nagios" module - it''s located in nagios/ >> >> manifests/ssa_nagios_checks.rb >> >> and looks like this >> >> >> hostclass :ssa_nagios_checks do >> >> ... >> >> end >> >> >> In nagios/manifests/init.pp I have >> >> >> class nagios::server { >> >> ... >> >> include ssa_nagios_checks >> >> ... >> >> } >> >> The autoloader/module layout recommendations/rules haven''t been followed. >> >> You actually want something more like: >> >> nagios/manifests/server.pp: >> >> class nagios::server { >> include nagios::ssa_nagios_checks >> } >> >> nagios/manifests/ssa_nagios_checks.rb: >> >> hostclass :''nagios::ssa_nagios_checks'' do >> notice(["should work"]) >> end >> >> This should work. Can you test it? >> >> Remember that sub-classes belong in their own file ... and only the >> class with the same name as the module belongs in init.pp. Also - you >> have to fully qualify class names when declaring them in their rb/pp >> file. >> >> ken. >> >> -- >> "Join us for PuppetConf, September 22nd and 23rd in Portland, OR:http://bit.ly/puppetconfsig" > > -- > You received this message because you are subscribed to the Google Groups "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en. > >-- "Join us for PuppetConf, September 22nd and 23rd in Portland, OR: http://bit.ly/puppetconfsig" -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
piavlo
2011-Aug-12 17:29 UTC
[Puppet Users] Re: need urgent help with including Ruby DSL class from puppet manifests
Thanks Ken that finaly solved the problem with the ruby dsl class and it''s working now. I don''t quite understand why you think implementing ruby function is better fit - what I need to do is iterate over all records in couchdb and create a puppet resource for each one of them - that''s the reason I use ruby dsl and not puppet defines. But how is puppet function going to help me - I won''t be able to reuse it in other places - so I don''t want to create a functions instead of each hostclass i need. Thanks On Aug 12, 12:17 am, Ken Barber <k...@puppetlabs.com> wrote:> Is it this line? > > raise Puppet:Error, "Unsupported ssa nagios check type $type" > > Should be double colon ... Puppet::Error. > > Looking at your code, I can''t help but think a function is a better > fit then Ruby DSL. > > ken. > > > > > > > > > > On Thu, Aug 11, 2011 at 9:34 PM, piavlo <lolitus...@gmail.com> wrote: > > Hi Ken, > > > Thank you so much for your reply > > I did like you said BUT i was still getting the error > > > err: Must pass a parameter or all necessary values at /etc/puppet/ > > modules/nagios/manifests/server.pp:19 on node mon1a.internal > > > Then I started to insert notice statement in the ruby DSL class - it > > turns out I a logical erro in the code. > > Arghhh - I have been so fooled by the totally misguiding error > > message. > > Shouldn''t puppet err indicate that there is problem in /etc/puppet/ > > modules/nagios/manifests/ssa_nagios_checks.rb and not in /etc/puppet/ > > modules/nagios/manifests/server.pp? > > > Anyway now that the ruby error is fixed I get new error > > err: undefined method `Puppet'' for #<Puppet::DSL::ResourceAPI: > > 0xb73f50e0> at /etc/puppet/modules/nagios/manifests/server.pp:15 on > > node mon1a.internal > > > What does this error means? > > > Here is the real ruby dsl class code - in case it''s again a problem > > with the class :) > > > ---------------- > > require ''json'' > > require ''open-uri'' > > > hostclass :''nagios::ssa_nagios_checks'' do > > > nagios_confdir = scope.lookupvar(''nagios::params::nrpe_confdir'') > > > url = "http://localhost:5984/nagios_alerts/_all_docs? > > include_docs=true" > > result = JSON.parse(open(URI.parse(url)).read) > > > result[''rows''].each do |x| > > > type = x[''doc''][''type''] > > args = x[''doc''][''args''] > > warning_threshold = x[''doc''][''warning_threshold''] > > critical_threshold = x[''doc''][''critical_threshold''] > > > contacts = x[''doc''][''contacts''] > > contact_groups = x[''doc''][''contact_groups''] > > notification_period = x[''doc''][''notifications_period''] > > > case type > > when "mysql" > > mysql_user = ''nagios'' > > mysql_password = ''xxxx'' > > check_command = "check_mysql_health_sql_tresholds!#{mysql_user}! > > #{mysql_password}!''#{args}''!#{warning_threshold}! > > #{critical_threshold}" > > when "api" > > check_command = "blah-blah" > > else > > raise Puppet:Error, "Unsupported ssa nagios check type $type" > > end > > > nagios_service( "ssa_#{x[''doc''][''_id'']}", > > :target => "${nagios_confdir}/app_alerts/ssa/ > > services/${name}.cfg", > > :host_name => x[''doc''][''hosts''], > > :service_description => x[''doc''][''desc''], > > :use => ''generic-service'', > > :check_command => check_command, > > :require => "File[#{nagios_confdir}/app_alerts/ssa/ > > services]" ) > > > end > > > end > > ---------------- > > > Thanks > > Alex > > > On Aug 11, 9:13 pm, Ken Barber <k...@puppetlabs.com> wrote: > >> If you look at this example: > > >> >> I have a Ruby class in "nagios" module - it''s located in nagios/ > >> >> manifests/ssa_nagios_checks.rb > >> >> and looks like this > > >> >> hostclass :ssa_nagios_checks do > >> >> ... > >> >> end > > >> >> In nagios/manifests/init.pp I have > > >> >> class nagios::server { > >> >> ... > >> >> include ssa_nagios_checks > >> >> ... > >> >> } > > >> The autoloader/module layout recommendations/rules haven''t been followed. > > >> You actually want something more like: > > >> nagios/manifests/server.pp: > > >> class nagios::server { > >> include nagios::ssa_nagios_checks > >> } > > >> nagios/manifests/ssa_nagios_checks.rb: > > >> hostclass :''nagios::ssa_nagios_checks'' do > >> notice(["should work"]) > >> end > > >> This should work. Can you test it? > > >> Remember that sub-classes belong in their own file ... and only the > >> class with the same name as the module belongs in init.pp. Also - you > >> have to fully qualify class names when declaring them in their rb/pp > >> file. > > >> ken. > > >> -- > >> "Join us for PuppetConf, September 22nd and 23rd in Portland, OR:http://bit.ly/puppetconfsig" > > > -- > > You received this message because you are subscribed to the Google Groups "Puppet Users" group. > > To post to this group, send email to puppet-users@googlegroups.com. > > To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. > > For more options, visit this group athttp://groups.google.com/group/puppet-users?hl=en. > > -- > "Join us for PuppetConf, September 22nd and 23rd in Portland, OR:http://bit.ly/puppetconfsig"-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Michael Field
2012-Dec-07 02:59 UTC
[Puppet Users] Re: need urgent help with including Ruby DSL class from puppet manifests
Error: Must pass a parameter or all necessary values at /etc/puppet/>Is because when using Ruby DSL, assumed variables $name and $title are not passed to Puppet resource. For example, fix this: create_resource :''server::vhost'', ''example'', :ensure => ''present'', etc... To this create_resource :''server::vhost'', :name => ''example'', :ensure => ''present'', etc... -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/1T9MWeV0AUkJ. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.