答案 0 :(得分:1)
总而言之,我会说不是原样。
你必须通过两次通过来调整工作。
您的第一个通行证将添加注册表信息,如果未将厨师作为服务安装,则在几分钟内计划一次厨师运行(在重新启动后定位),然后重新启动。
第二遍应该遍历注册表部分并完成剩下的安装。
根据您的代码并假设Chef在节点上作为自动启动服务安装,您可以为您的powershell资源添加一个警卫,如下所示:
powershell_script "install-Sharepoint2007-PREREQUISITES" do
code <<-EOH
regedit /s .\appcompat.reg
EOH
notifies :reboot_now, 'reboot[Restart Computer]', :immediately
not_if registry_data_exists?(
KEY_PATH,
{ :name => "NAME", :type => TYPE, :data => VALUE },
ARCHITECTURE
)
end
答案 1 :(得分:1)
您可以让厨师在启动时运行计划任务以运行厨师。
windows_task 'Chef client' do
user 'SYSTEM'
command 'chef-client -L C:\chef\chef-client.log'
run_level :highest
frequency :onstart
frequency_modifier 30
action :create
end
然后当节点重新启动时,厨师将再次运行。
考虑以下配方,将Windows计算机加入域,重新启动,运行chef(作为计划任务),然后删除计划任务。
https://github.com/NetDocuments/ad-join-cookbook/blob/master/resources/domain_join.rb
更新有一项RFC提议可以更改主厨的退出代码,以便能够以智能方式处理重新启动。
答案 2 :(得分:0)
我使用FLAG文件方法完成了它,下面给出了示例。 域加入示例 -
---------------------------Script Start------------------------
powershell_script 'Domain_Join' do
guard_interpreter :powershell_script
code -domainJoin
$currentTime = Get-Date
$currentTimeString = $currentTime.ToString()
$systemDomain = (Get-WmiObject Win32_ComputerSystem).Domain
If (($systemDomain) -eq 'domainName')
{
Try {
write-host "$env:computerName is DOMAIN MEMBER"
Remove-Item C:\\DomainJoinFlag.txt -ErrorAction Stop
Unregister-ScheduledTask -TaskName "Chef client schedule_DJ" -Confirm:$false
} # end of Try
Catch [System.Management.Automation.ItemNotFoundException]
{ write-host "Server is already domain member, Or Exception raised due to either missing FLAG file or Server startup schedule task configuration."
eventcreate /t INFORMATION /ID 0909 /L APPLICATION /SO "ChefClient_$env:computerName" /D "Server is already domain member, Or Exception raised due to either missing FLAG file or Server startup schedule task configuration. Refer to the CHEF reciepie for DomainJoin or check Administrative credentials for creting schedule task"}
}
else { write-host "$env:computerName is NOT domain member, joining the server to the domain. Server will be rebooting in a while..."
eventcreate /t INFORMATION /ID 0909 /L APPLICATION /SO "ChefClient_$env:computerName" /D "Joining the server : $env:ComputerName to the domain ININLAB.COM (Server Time): $currentTimeString"
New-Item C:\\DomainJoinFlag.txt -type file -force
write-host "$env:computerName DOMAIN JOIN INITIATED for the server"
$cred = New-Object System.Management.Automation.PsCredential("domain\\domain_user", (ConvertTo-SecureString "Password" -AsPlainText -Force))
Add-Computer -DomainName "domainName" -Credential $cred -OUPath "OU=HyperV,OU=Infrastructure,OU=Servers,DC=domain,DC=name"
shutdown -r -t 120
} #end_of_else
domainJoin
notifies :run, 'windows_task[Chef client schedule_DJ]', :immediately
end
windows_task 'Chef client schedule_DJ' do
user 'SYSTEM'
command 'chef-client -L C:\chef\chef-client_after_reboot_domainJoin.log'
run_level :highest
frequency :onstart
frequency_modifier 30
action :create
only_if { ::File.exist?('C:\\DomainJoinFlag.txt') }
end
---------------------------Script Ends------------------------
答案 3 :(得分:-1)
使用 rakefile 来触发收敛。你应该在Windows重启后给一些休眠时间并再次重新收敛:这是例子。
sh 'bundle exec kitchen converge'
sleep 120
sh 'bundle exec kitchen verify'