[chef] Re: RE: Re: LWRPs and rolling back


Chronological Thread 
  • From: Dan Razzell < >
  • To:
  • Subject: [chef] Re: RE: Re: LWRPs and rolling back
  • Date: Wed, 09 Oct 2013 11:38:08 -0700

Others have commented that it may be best to keep the workflow within the provider.

If you truly need to do workflow within the recipe, it will be a bit awkward to express.  Resource notifications are performed on success, not on failure.  To fire the rollback on failure, you'd have to do something like the following:
foo_validated = false

ruby_block "foo_validated" do
  action :nothing
  block do
    foo_validated = true
  end
end

my_resource "foo validate" do
  name "foo-1"
  action :validate
  notifies :create, "ruby_block[foo_validated]", :immediately
  ignore_failure true
end

my_resource "foo rollback" do
  name "foo-1"
  action :rollback
  not_if { foo_validated }
end
Cheers,
Dan

On 13-10-09 10:22 AM, Florian Hehlen wrote:
" type="cite">

Greg,

 

Thanks for the quick response.  The main thing is that I want to be able to call :rollback only if :validation fails or in a couple of other places where fatal errors can occur and just stopping is not good enough.

 

Cheers,

Florian

 

From: Greg Symons [ ">mailto: ]
Sent: 09 October 2013 19:12
To: ">
Subject: [chef] Re: LWRPs and rolling back

 

On 10/09/13 09:32, Florian Hehlen wrote:

HI all,

 

I am writting my own LWRP for my server. So I have the following actions:

 

actions :stop, :db_backup, :update, :validate, :db_rollback, :server_rollback, :start

 

creating the resource/provider is working pretty well. I am wondering though how I can express the workflow logic in the recipe to roll-back only if the validation fails.

 

I see some possibilities with handlers, or with the only_if/not_if properties, notifiers/subscribers but none of them scream out as the way to go. Are there any suggestions on best practices here?

 

cheers,

Florian

Let the provider handle the sequencing. So, in your example, I'd define methods in the provider for each of the steps you currently have as actions, and then in the actual actions, call them in the right order:

action :stop do
  doStop
end

action :backup do
  doStop
  doBackup
end

action :update do
  doUpdate
  doRollback unless doValidate
end

action :rollback do
  doRollback
end

action :validate do
  doValidate
end

action :start do
  doStart
end

I don't actually know the rules of your workflow, so those may not be right. In fact, if there are things in your workflow you'd really never do separately from other things, then I wouldn't even expose those as separate actions.

Greg




Archive powered by MHonArc 2.6.16.

§