Windows Update Chef Recipe

时间:2013-11-28 16:27:51

标签: windows chef

我正在尝试使用以下主厨配方在亚马逊云中的Windows 2008 R2计算机上下载和安装Windows更新:https://github.com/dougm/site-cookbooks/blob/master/windows/recipes/update.rb

我正在使用Chef 11.8.0但是主厨运行失败并出现以下错误:

c:/chef/cache/cookbooks/test/recipes/updates.rb中的配方编译错误

WIN32OLERuntimeError


(在OLE方法`CreateUpdateDownloader'中:)      OLE错误代码:80070005 in              HRESULT错误代码:0x80020009        发生了例外。

食谱追踪:


c:/chef/cache/cookbooks/test/recipes/updates.rb:54:in method_missing' c:/chef/cache/cookbooks/test/recipes/updates.rb:54:in from_file'

第54行:downloader = session.CreateUpdateDownloader。

有什么想法吗?

3 个答案:

答案 0 :(得分:0)

错误来自this line of code。该错误与Chef无关,而WIN32OLE正在引发该异常。

我会尝试在交互式Ruby(irb)中运行代码,看看是否有更有用的错误。

答案 1 :(得分:0)

就像sethvargo所说,这不是直接的厨师代码问题。 “代码:80070005”和“错误代码0x80020009”都是权限问题。尝试确认Chef在Windows服务器上运行的用户上下文。 Chef是作为服务安装和运行还是触发厨师 - 客户端执行?

答案 2 :(得分:0)

#
# Cookbook Name:: InstallWindowsUpdates
# Recipe:: default
# Author(s):: A M
#

# Configures Windows Update automatic updates
powershell_script "install-windows-updates" do
  guard_interpreter :powershell_script
  # Set a 2 hour timeout
  timeout 7200
  code <<-EOH
    Write-Host -ForegroundColor Green "Searching for updates (this may take up to 30 minutes or more)..."

    $updateSession = New-Object -com Microsoft.Update.Session
    $updateSearcher = $updateSession.CreateupdateSearcher()
    try
    {
      $searchResult =  $updateSearcher.Search("Type='Software' and IsHidden=0 and IsInstalled=0").Updates
    }
    catch
    {
      eventcreate /t ERROR /ID 1 /L APPLICATION /SO "Chef-Cookbook" /D "InstallWindowsUpdates: Update attempt failed."
      $updateFailed = $true
    }

    if(!($updateFailed)) {
      foreach ($updateItem in $searchResult) {
        $UpdatesToDownload = New-Object -com Microsoft.Update.UpdateColl
        if (!($updateItem.EulaAccepted)) {
          $updateItem.AcceptEula()
        }
        $UpdatesToDownload.Add($updateItem)
        $Downloader = $UpdateSession.CreateUpdateDownloader()
        $Downloader.Updates = $UpdatesToDownload
        $Downloader.Download()
        $UpdatesToInstall = New-Object -com Microsoft.Update.UpdateColl
        $UpdatesToInstall.Add($updateItem)
        $Title = $updateItem.Title
        Write-host -ForegroundColor Green "  Installing Update: $Title"
        $Installer = $UpdateSession.CreateUpdateInstaller()
        $Installer.Updates = $UpdatesToInstall
        $InstallationResult = $Installer.Install()
        eventcreate /t INFORMATION /ID 1 /L APPLICATION /SO "Chef-Cookbook" /D "InstallWindowsUpdates: Installed update $Title."
      }

      if (!($searchResult.Count)) {
        eventcreate /t INFORMATION /ID 999 /L APPLICATION /SO "Chef-Cookbook" /D "InstallWindowsUpdates: No updates available."
      }
      eventcreate /t INFORMATION /ID 1 /L APPLICATION /SO "Chef-Cookbook" /D "InstallWindowsUpdates: Done Installing Updates."
    }
  EOH
  action :run
end