Exiting a run mid way through


#1

Hello all,
I’m looking for a way to exit a chef run gracefully(including calling handlers) if a specific resource is notified. I am using the reboot handler used in the windows cookbook. I would like the chef run to stop if this resource provider is called so a reboot can be processed. Is there an easy way to accomplish this?

Kendrick


#2

Just raise an exception, it will abort the run.

–Noah

On Apr 16, 2012, at 1:18 PM, Kendrick Martin wrote:

Hello all,
I’m looking for a way to exit a chef run gracefully(including calling handlers) if a specific resource is notified. I am using the reboot handler used in the windows cookbook. I would like the chef run to stop if this resource provider is called so a reboot can be processed. Is there an easy way to accomplish this?

Kendrick


#3

I believe I’ve used ‘return’ in a run to halt its processing by the
recipe compiler, too, although you’ll have to test it works as you
expect.

return ArgumentError unless node.foo.has_key? :bar

–AJ

On 17 April 2012 10:12, Noah Kantrowitz noah@coderanger.net wrote:

Just raise an exception, it will abort the run.

–Noah

On Apr 16, 2012, at 1:18 PM, Kendrick Martin wrote:

Hello all,
I’m looking for a way to exit a chef run gracefully(including calling handlers) if a specific resource is notified. I am using the reboot handler used in the windows cookbook. I would like the chef run to stop if this resource provider is called so a reboot can be processed. Is there an easy way to accomplish this?

Kendrick


#4

****drrrrp:

return unless node.foo.has_key? :bar

–AJ

On 17 April 2012 10:16, AJ Christensen aj@junglist.gen.nz wrote:

I believe I’ve used ‘return’ in a run to halt its processing by the
recipe compiler, too, although you’ll have to test it works as you
expect.

return ArgumentError unless node.foo.has_key? :bar

–AJ

On 17 April 2012 10:12, Noah Kantrowitz noah@coderanger.net wrote:

Just raise an exception, it will abort the run.

–Noah

On Apr 16, 2012, at 1:18 PM, Kendrick Martin wrote:

Hello all,
I’m looking for a way to exit a chef run gracefully(including calling handlers) if a specific resource is notified. I am using the reboot handler used in the windows cookbook. I would like the chef run to stop if this resource provider is called so a reboot can be processed. Is there an easy way to accomplish this?

Kendrick


#5

return aborts the current recipe during the compile phase, but it wouldn’t have any affect on later recipes or during run. Useful more for stuff like per-platform guard clauses.

–Noah

On Apr 16, 2012, at 3:16 PM, AJ Christensen wrote:

I believe I’ve used ‘return’ in a run to halt its processing by the
recipe compiler, too, although you’ll have to test it works as you
expect.

return ArgumentError unless node.foo.has_key? :bar

–AJ

On 17 April 2012 10:12, Noah Kantrowitz noah@coderanger.net wrote:

Just raise an exception, it will abort the run.

–Noah

On Apr 16, 2012, at 1:18 PM, Kendrick Martin wrote:

Hello all,
I’m looking for a way to exit a chef run gracefully(including calling handlers) if a specific resource is notified. I am using the reboot handler used in the windows cookbook. I would like the chef run to stop if this resource provider is called so a reboot can be processed. Is there an easy way to accomplish this?

Kendrick


#6

My trouble is, I’m trying to find a way to return(and thus end) as part of the run, not the compile. I also can’t raise an Exception because I need the run to complete successfully so the report handlers will run.

-----Original Message-----
From: Noah Kantrowitz [mailto:noah@coderanger.net]
Sent: Monday, April 16, 2012 3:19 PM
To: chef@lists.opscode.com
Subject: [chef] Re: Re: Re: Exiting a run mid way through

return aborts the current recipe during the compile phase, but it wouldn’t have any affect on later recipes or during run. Useful more for stuff like per-platform guard clauses.

–Noah

On Apr 16, 2012, at 3:16 PM, AJ Christensen wrote:

I believe I’ve used ‘return’ in a run to halt its processing by the
recipe compiler, too, although you’ll have to test it works as you
expect.

return ArgumentError unless node.foo.has_key? :bar

–AJ

On 17 April 2012 10:12, Noah Kantrowitz noah@coderanger.net wrote:

Just raise an exception, it will abort the run.

–Noah

On Apr 16, 2012, at 1:18 PM, Kendrick Martin wrote:

Hello all,
I’m looking for a way to exit a chef run gracefully(including calling handlers) if a specific resource is notified. I am using the reboot handler used in the windows cookbook. I would like the chef run to stop if this resource provider is called so a reboot can be processed. Is there an easy way to accomplish this?

Kendrick


#7

No. Why do you not want the rest of the chef run to continue? If the
resources are idempotent, it shouldn’t make more than a small amount
of difference.

I can think of some ways you can hack this, but really, are you sure
this is the behavior you really want?

Adam

On Mon, Apr 16, 2012 at 1:18 PM, Kendrick Martin
Kendrick.Martin@webtrends.com wrote:

Hello all,
I’m looking for a way to exit a chef run gracefully(including calling
handlers) if a specific resource is notified. I am using the reboot handler
used in the windows cookbook. I would like the chef run to stop if this
resource provider is called so a reboot can be processed. Is there an easy
way to accomplish this?

Kendrick


Opscode, Inc.
Adam Jacob, Chief Customer Officer
T: (206) 619-7151 E: adam@opscode.com


#8

On Windows, if UAC is enabled for example, I want to disable it, call the reboot handler and exit the run right away. Things further down the run might hit issues if UAC isn’t disabled before hand.

-----Original Message-----
From: Adam Jacob [mailto:adam@opscode.com]
Sent: Tuesday, April 17, 2012 10:51 AM
To: chef@lists.opscode.com
Subject: [chef] Re: Exiting a run mid way through

No. Why do you not want the rest of the chef run to continue? If the resources are idempotent, it shouldn’t make more than a small amount of difference.

I can think of some ways you can hack this, but really, are you sure this is the behavior you really want?

Adam

On Mon, Apr 16, 2012 at 1:18 PM, Kendrick Martin Kendrick.Martin@webtrends.com wrote:

Hello all,
I’m looking for a way to exit a chef run gracefully(including calling
handlers) if a specific resource is notified. I am using the reboot
handler used in the windows cookbook. I would like the chef run to
stop if this resource provider is called so a reboot can be processed.
Is there an easy way to accomplish this?

Kendrick


Opscode, Inc.
Adam Jacob, Chief Customer Officer
T: (206) 619-7151 E: adam@opscode.com


#9

There may be hacks you can do that will work “better”, but they’ll be
more brittle. I would recommend:

You do something like:

ruby_block “stop now” do
code do
raise "This is really okay, man"
end
action :nothing
end

Then have an error handler that looks for that exception, and if it
finds it, triggers the normal exception handlers.

Ugly, but it’ll work.

Adam

On Tue, Apr 17, 2012 at 11:34 AM, Kendrick Martin
Kendrick.Martin@webtrends.com wrote:

On Windows, if UAC is enabled for example, I want to disable it, call the reboot handler and exit the run right away. Things further down the run might hit issues if UAC isn’t disabled before hand.

-----Original Message-----
From: Adam Jacob [mailto:adam@opscode.com]
Sent: Tuesday, April 17, 2012 10:51 AM
To: chef@lists.opscode.com
Subject: [chef] Re: Exiting a run mid way through

No. Why do you not want the rest of the chef run to continue? If the resources are idempotent, it shouldn’t make more than a small amount of difference.

I can think of some ways you can hack this, but really, are you sure this is the behavior you really want?

Adam

On Mon, Apr 16, 2012 at 1:18 PM, Kendrick Martin Kendrick.Martin@webtrends.com wrote:

Hello all,
I’m looking for a way to exit a chef run gracefully(including calling
handlers) if a specific resource is notified. I am using the reboot
handler used in the windows cookbook. I would like the chef run to
stop if this resource provider is called so a reboot can be processed.
Is there an easy way to accomplish this?

Kendrick


Opscode, Inc.
Adam Jacob, Chief Customer Officer
T: (206) 619-7151 E: adam@opscode.com


Opscode, Inc.
Adam Jacob, Chief Customer Officer
T: (206) 619-7151 E: adam@opscode.com