ruby_block条件语句并等待重新启动



我从厨师 IRC 的 coderanger 那里得到了一些很好的指导,我不想进一步打扰他,但这是我的问题:

我的目标是运行配方一,然后

运行配方二,然后在保持厨师运行的同时重新启动,然后执行配方三。我想我已经接近了,但仍然遇到错误。我不确定这是我的代码块还是Windows的行为方式。

这是我的代码块:

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

该块执行没有问题,但它似乎很快移动到 stuff::three 配方,这会导致此错误,因为 powershell 不可用,因为机器仍在启动:

==> 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.

我认为一旦发出重新启动命令,几秒钟后就不再有挂起的重新启动。那么,有没有不同的红宝石助手可以使用我的while?还是这个块只是废话?

所以我在这里也回答了很多问题。不过谢谢你的想法。

你一直试图把include_recipe放在while循环的主体中,这不是你想要的,我不认为。这说"在重新启动挂起时一遍又一遍地包含它"。

你想要的是这个:

include_recipe 'stuff::reboot'
ruby_block 'wait for reboot' do
  block do
    true while reboot_pending?
  end
end
include_recipe 'stuff::three'

这将在两个配方的内容之间的集合中放置一个资源,如果重新启动挂起,则会停止收敛,否则它会继续。

最新更新