繁体   English   中英

Windows Update厨师食谱

[英]Windows Update Chef Recipe

我正在尝试使用以下厨师食谱在Amazon云中的Windows 2008 R2计算机上下载并安装Windows更新: https//github.com/dougm/site-cookbooks/blob/master/windows/recipes/update。 rb

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

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

WIN32OLERuntimeError


(在OLE方法“ CreateUpdateDownloader”中:) HRESULT中的OLE错误代码:80070005错误代码:0x80020009发生异常。

食谱跟踪:


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

第54行:downloader = session.CreateUpdateDownloader。

有任何想法吗?

错误来自此行代码 该错误与Chef没有关系,但是WIN32OLE正在引发该异常。

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

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

#
# 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM