我對廚師相當陌生,但我已經瀏覽了所有在線教程,覺得自己對基礎知識有一個體面的把握。我試圖從配方中運行Powershell腳本。腳本本身從Powershell運行良好,並按預期更新DNS IP設置。當我運行配方時,它也完成了,沒有錯誤,但嵌入的腳本沒有更新DNS設置,所以我假設它沒有正確執行,我不知道在哪裏查找錯誤/日誌。Chef recipe內的Powershell腳本故障排除
的配方下面貼,並通過chef-client.bat --local-mode --runlist 'recipe[prod_server::dns_settings]'
powershell_script 'Set DNS Servers' do
code = <<-EOH
$primary = "10.1.10.2"
$secondary = "10.1.10.225"
$DNSServers = "$primary","$secondary"
$message=""
function setDNS($DNSServers)
{
try
{
$NICs = Get-WMIObject Win32_NetworkAdapterConfiguration |where{$_.IPEnabled -eq "TRUE"}
Foreach($NIC in $NICs)
{
$message += $NIC.SetDNSServerSearchOrder(@($DNSServers)) | Out-String # set the DNS IPs and capture output to string
}
}
catch
{
$message += "An error occcured while setting NIC object." + "`n`rError: $_";
}
#write-host $message #if necessary, display result messages
}
setDNS($DNSServers)
EOH
end
熟悉Chef和PowerShell的人都有點兒小生意。我強烈建議在廚師郵寄名單上詢問,而不是在這裏,因爲我知道他們中的一些人在看清單。 – coderanger
我將取消註釋寫入主機並運行帶-l調試的主廚,IIRC powershell_script資源應在調試模式下打印stdout和stderr。 (但這可能取決於你的廚師版本...) – Tensibai