ruby_block 条件语句并等待重启

ruby_block conditional statement and waiting for reboot

我从 Chef 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.

我在想,一旦发出重启命令,几秒钟后就不再有挂起的重启。那么,是否有不同的 ruby 帮助器来使用我的 while 呢?或者这个区块只是垃圾?

太好了,我也在这里回答了很多问题。谢谢你的想法。

你一直试图将 include_recipe 放在 while 循环的主体中,我不认为这不是你想要的。也就是说 "include this over and over while a reboot is pending".

你要的是这个:

include_recipe 'stuff::reboot'

ruby_block 'wait for reboot' do
  block do
    true while reboot_pending?
  end
end

include_recipe 'stuff::three'

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