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


Chronological Thread 
  • From: Jesse Nelson < >
  • To: " " < >
  • Cc: "< >" < >
  • Subject: [chef] Re: RE: Re: LWRPs and rolling back
  • Date: Wed, 9 Oct 2013 11:11:23 -0700

You may want to rescue your actions in your provider and not expose an action :rollback. You could set a resource attribute that enables rollback capability. 




On Oct 9, 2013, at 10:22 AM, "Florian Hehlen" < "> > wrote:

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

 

 

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.

§