我当前正在尝试使用chef资源中的reboot资源:
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我得到了一个无穷无尽的重启循环(client reboots ->chef client run-->chef client reruns run_list--client reboots->...)。我怎么能只重启一次?
发布于 2020-01-29 23:57:40
您可以添加一些验证,以检查计算机是否已重新启动一次。
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运行时,该文件将存在,因此不会触发重新启动。
发布于 2020-01-31 14:23:45
来自reboot厨师资源:
使用重新启动资源来重新启动节点,对于某些平台上的某些安装,这是一个必要的步骤。此资源支持在Microsoft Windows、macOS和Linux平台上使用。
reboot 'name' do
action :reboot_now
end发布于 2020-02-03 20:35:34
如果ENV['JAVA_HOME'] 不为空,则您在ENV['JAVA_HOME']资源中的only_if保护将使execute资源运行。很可能设置了这个环境变量,这就是每次Chef运行时运行execute资源并触发重启的原因。
我的猜测是,只有在变量为空的情况下,您才需要一个相反的方法,即运行资源。为此,您只需从行中删除!即可。
only_if { ENV['JAVA_HOME'].to_s.empty? }如果我之前的猜测是错误的,那么您需要将您的only_if防护更改为更健壮的保护。在命令行中,我知道你创建了一些配置文件,所以当你的配置文件已经存在时,你不需要运行execute资源:
not_if { ::File.exist?('/path/to/file/created/by/command') }https://stackoverflow.com/questions/59970618
复制相似问题