Reputation: 605
I got some great direction from coderanger on chef IRC and I didn't want to bug him further but here's my problem:
My goal is to run recipe one, then two, then reboot while keeping the chef run alive, then execute recipe three. I think I'm close but still running into errors. I'm not sure if it's my code block or the way Windows behaves.
Here's my code block:
ruby_block "test" do
block do
run_context.include_recipe "stuff::reboot"
while reboot_pending? == true do
run_context.include_recipe "stuff::three"
end
end
end
The block executes with no issue but it seems to move on quickly to the stuff::three recipe which causes this error because powershell isn't available since the machine is still booting up:
==> default: The argument 'c:/tmp/vagrant-elevated-shell.ps1' to the -File parameter does not exist. Provide the path to an existing '.ps1' file as an argument to the -File parameter.
I'm thinking that once the reboot command is issued, after a few seconds there is no longer a pending reboot. So, is there a different ruby helper to use my while with? Or is this block just crap?
Upvotes: 1
Views: 233
Reputation: 54211
Sooooo I answer a lot of the questions here too. Thanks for the thought though.
You keep trying to put the include_recipe
in the body of the while loop, which isn't what you want I don't think. That says "include this over and over while a reboot is pending".
What you want is this:
include_recipe 'stuff::reboot'
ruby_block 'wait for reboot' do
block do
true while reboot_pending?
end
end
include_recipe 'stuff::three'
That will put a resource in the collection between the stuff from the two recipes that halts the converge if a reboot is pending, otherwise it continues.
Upvotes: 2