[chef] Re: Re: Re: Re: Library function in recipe


Chronological Thread 
  • From: Vinod Guddad < >
  • To:
  • Subject: [chef] Re: Re: Re: Re: Library function in recipe
  • Date: Sun, 12 Aug 2012 22:09:53 -0700

I ended up creating a LWRP for this. The LWP uses the library created earlier.

Thank you for the suggestions.

On Wed, Aug 8, 2012 at 3:34 PM, AJ Christensen < " target="_blank"> > wrote:
Post the stack trace with log level set to :debug

You probably want something like below in your library file:

Chef::Recipe.send(:include, EventLogLib)

https://github.com/fujin/chef-discovery/blob/master/libraries/recipe.rb#L17

You could model this as an LWRP, or even one of the new conditional
output formatters in 10.14, similar to specdoc -- queuedoc or
something. :) (perhaps?)

--AJ

On 9 August 2012 08:11,  < "> > wrote:
> I am getting a method not defined exception with the following code in the
> recipe. I tried both the commented and un-commented lines in the ruby_block
> below and both did not work.
> The library is listed below as well.
>
> <code>
> class Chef::Recipe
>   include EventLogLib
> end
>
> ruby_block "mystart" do
> block do
> #EventLogLib.logEvent("def","START")
> logEvent("def","START")
> end
> end
> </code>
>
> Here is the library defined in the cookbook.
> <code>
> module EventLogLib
>   def logEvent(msg, msgstatus)
>         require "rubygems"
>         require "stomp"
>         stomp_server = node[:chef_handler][:stomp_server]
>         stomp_port = node[:chef_handler][:stomp_port]
>         stomp_queue = node[:chef_handler][:stomp_queue]
>         stomp_user = node[:chef_handler][:stomp_user]
>         stomp_password =  node[:chef_handler][:stomp_password]
>         eventQueue = "#{stomp_queue}"
>
>         summary = { :deploymentId => node.deployment_id,
>                                 :vmId => node.vm_id,
>                                 :vmHostname => node.hostname,
>                                 :vmIpaddress => node.ipaddress,
>                                 :stepMessage => msg,
>                                 :stepStatus => msgstatus
>                           }
>
>         client = Stomp::Client.new(stomp_user, stomp_password, stomp_server,
> stomp_port, true)
>         client.publish(eventQueue, summary.to_json, {:persistent => false})
>         client.close
>         Chef::Log.info ("message #{summary.to_json} sent to queue
> #{eventQueue}")
>   end
> end
> </code>




Archive powered by MHonArc 2.6.16.

§