我当前正在尝试在厨师资源中使用重新启动资源:
reboot 'ADS Install Complete' do
action :nothing
reason 'Cannot continue Chef run without a reboot.'
only_if {reboot_pending?}
end
...
execute 'Initialize ADS Configuration INI' do
command "\"#{node["ads-tfs-ini"]["tfsconfig_path"]}\" unattend \/create \/type:#{node["ads-tfs-ini"]["Scenario"]} \/unattendfile:\"#{node["ads-tfs-ini"]["unattend_file_path"]}\""
only_if { ! "#{ENV['JAVA_HOME']}".to_s.empty? }
notifies :request_reboot, 'reboot[ADS Install Complete]', :delayed
end
我正在经历一个无休止的重启循环(客户端重启-> chef客户端运行-> chef客户端重新运行run_list-client重启-> ...)。我怎样才能重启一次?
您可以添加一些验证以检查计算机是否已重新启动一次。
ruby_block "reboot" do
unless File.exist?("C:\reboot") do
block do
Chef::Util::FileEdit.new('C:\reboot').write_file
Chef::ShellOut.new("shutdown /r").run_command
end
end
end
此解决方案并不是很好,但是应该可以。重启位于ruby块内部,只有在C:\ reboot不存在的情况下才会运行。如果该文件不存在,则该块将创建该文件,然后调用重新引导。在第二次运行Chef时,该文件将存在,因此不会触发重新启动。