[chef] Re: Re: Re: Re: Re: Re: How to suppress notifications in LWRP


Chronological Thread 
  • From: Sean OMeara < >
  • To: " " < >
  • Cc: Fabry Zio < >
  • Subject: [chef] Re: Re: Re: Re: Re: Re: How to suppress notifications in LWRP
  • Date: Tue, 23 Apr 2013 12:04:10 -0400


You need to add convergence checks to all your execute/bash resources.

The whole point of the use_inline_resources, is so that if any nested resources need to fix their subject, the caller will be updated too. 'execute' and 'script' type resources need to guarded by not_if/only_if, or have an action of :nothing, and be triggered by something else.

The actions in the LWRP DSL should be thought of as the state the resource needs to be in.... 
..so in gistfile1.txt, you want the contents of :initialize actions that "put this into the state of being initialized"

If you use nothing but core resource (file/template/cron/mount/etc), this is transparent and magic. If you step outside those and start using execute/script or "raw" ruby to change system state, it is your responsibility to make sure that action is only taken when necessary.

Basically, you want to refactor everything to look like this:

ruby_block "create_key_files" do
block do
puts "#{blawk blawk}"
do
not_if { CODE THAT DETERMINES IF THE KEYFILES ARE ALREADY CREATED }
end

ruby_block "create_ca_files" do
block do
puts "#{blawk blawk}"
end
not_if { CODE THAT DETERMINES IF THE CA FILES ARE ALREADY CREATED }
end

bash "add_server_keys" do
command "echo #{bash bash}"
not_if "test is the sever_keys are already added"
end


Now, this being said... this particular problem looks like its going to require some non-trivial code in the test sections.
To help with this, you can factor out some of the convergence tests into the libraries directory if your cookbook

# recipes/my_recipe.rb

ruby_block "promise a thing" do
  block do
     puts "my_block"
  end
  not_if { some_function }
  only_if { some_other_function }
end

# libraries/default.rb

def some_function
   # a bunch of detective work
end

def some_other_function
   # a bunch of detective work
end


Hope this helps, and good luck!

-s

On Tue, Apr 23, 2013 at 11:44 AM, Daniel DeLeo < " target="_blank"> > wrote:

On Tuesday, April 23, 2013 at 8:24 AM, Fabry Zio wrote:

Hi Sean,

this is the snippet that initializes the WSO2 server:     https://gist.github.com/FabryZio/5444480

and this is the snippet that tries to modify the keystores:     https://gist.github.com/anonymous/5444348

They are all parts of the LWRP

Thank you
If I were you, I'd look at making at least two LWRPs out of this. First of all, take all the keystore stuff out, and make a LWRP. In that LWRP, it'll be much easier if you avoid using Chef resources and instead use lower level stuff like shell_out. Then make your app server LWRP use the keystore LWRP.

-- 
Daniel DeLeo





Archive powered by MHonArc 2.6.16.

§