由chef-client运行时,DISM / SQL2012无法访问Windows Update

时间:2013-05-15 16:55:03

标签: sql-server-2012 chef windows-server-2012 winrm

我的问题是:在通过WinRM运行厨师时,是否存在某种权限问题,该程序不允许程序进入互联网?

我正在尝试在Server 2012 Std上使用Chef 11.4.4来部署SQL 2012 Std。我遇到了两个问题,我相信它们是相关的:

windows_feature "NetFx3" do
  action :install
end

这失败了因为DISM应该去微软更新并下载.Net 3.5.1文件。如果我通过RDP手动运行DISM /online /enable-feature /featurename:NetFx3 /norestart,它工作正常 - 这基本上就是windows_feature的运行。

如果我通过配方(带有DVD)运行DISM /online /enable-feature /featurename:NetFx3 /norestart /LimitAccess /Source:d:\sources\sxs,它就可以了。实际上,这绕过了下载文件的需要。

第二个问题是SQL Server 2012安装程序尝试在安装期间联机查找更新。如果我将/ UpdateEnabled = false开关添加到install命令,它将继续。我正在使用

windows_package "Microsoft SQL Server 2012 (64-bit)" do
  source "\\\\10.200.1.240\\admin\\Installs\\SQL\\SQL2012Std\\setup.exe"
  timeout 3600 # 60min to just install sql will be fine. Default of 10min can be a bit short
  action :install
  installer_type :custom
  options "/ConfigurationFile=\"#{node['mssql']['installIni']}\" /SAPWD=\"#{node['mssql']['sapw']}\""
end

在installIni文件中,我的设置为UpdateSource=MU

如果这有所不同,我将通过knife winrm 192.168.170.145 'chef-client -c c:/chef/client.rb' -m -x nfox运行厨师。当我从管理员运行chef-client时,我没有遇到此问题:cmd窗口。

1 个答案:

答案 0 :(得分:0)

是的,winrm(厨师通信协议)没有完整的用户" context"与您在本地执行命令相比(即使以本地管理员特权用户或本地管理员身份执行此操作)。

之前提到的解决方案是使用计划任务,它会异步启动计算机。这样做的好处是具有完整的上下文,但是在计划任务完成后需要知道的缺点是删除它并继续。至于使用预定任务,你应该使用具有lwrp的windows cookbook。

所以...安装NetFx3功能的解决方案(Microsoft SQL Server 2012(64位)安装解决方案可以使用相同的计划任务方法完成):

  • 捕获错误(这只会在第一次运行时发生 食谱;安装功能后运行不会抛出错误)和 在计划任务中处理它;厨师的错误处理是一个漫长的过程 主题,但简而言之,您只能在此期间捕获厨师错误 "编译"厨师跑的阶段,那是什么end.run_action( :install)正在做)
  • 创建并运行计划任务
  • 轮询直到安装该功能或超过超时
  • 无论安装功能的成功与否,始终删除任务
  • 根据成功/失败的功能安装进行

创建包含

的COOKBOOK / files / default / install_dotnetfx3.bat.erb
dism.exe /online /enable-feature /featurename:NetFx3 /norestart

然后将其作为食谱的一部分

begin
  windows_feature "NetFx3ServerFeatures" do
    action :nothing
  end.run_action( :install )

  windows_feature "NetFx3" do
    action :nothing
  end.run_action( :install )

rescue Mixlib::ShellOut::ShellCommandFailed => ex

  Chef::Log.error( "ShellCommandFailed was thrown during windows_feature NetFx3 install. Kicking off install via windows_task." )

  install_dotnet3_task   = 'install_dotnetfx3'
  install_dotnet3_script = 'C:\Chef\install_dotnetfx3.bat'

  # :create cookbook_file in "compile" phase
  cookbook_file install_dotnet3_script do
    source 'install_dotnetfx3.bat.erb'
    action :nothing
  end.run_action( :create )

  # :create windows_task in "compile" phase
  windows_task install_dotnet3_task do
    user Administrator
    password XXXXXXX
    command install_dotnet3_script 
    run_level :highest
    action :nothing  
    frequency :minute
    frequency_modifier 10
  end.run_action( :create )

  # :run windows_task in "compile" phase
  windows_task install_dotnet3_task do
    action :nothing
  end.run_action( :run )

  featureInstalled = false
  iteration = 0
  # number of sleeps each sleep_period seconds (total_sleep_period =     max_dotnet3_install_via_task_loop_counter * sleep_period)
  max_dotnet3_install_via_task_loop_counter = 10
  sleep_period = 20 # in sec
  loop do

    # Check if feature is installed
    featureInstalled = shell_out( "dism /online /get-featureinfo /FeatureName:NetFx3 | find \"State : Enabled\"" ).exitstatus == 0 
    break if featureInstalled || ( iteration += 1 ) > max_dotnet3_install_via_task_loop_counter

    # sleep for sleep_period seconds
    sleep sleep_period

    log "Inside of polling loop for installation (taking #{(iteration * sleep_period)} seconds) of feature via windows_task." do
      level :info
      action :nothing
    end.run_action( :write )
  end

  # Always :delete windows_task (so that it won't fire again with frequency above) in "compile" phase regardless of whether 
  # installation via task succeeded or failed.
  windows_task install_dotnet3_task do
    action :nothing
  end.run_action( :delete )

  if featureInstalled
    log "Installation of the feature via windows_task succeeded." do
      level :info
      action :nothing
    end.run_action( :write )
  else
    # Raise exception if installation via windows_task failed
    raise "Installation of the feature via windows_task timed out within #{(max_dotnet3_install_via_task_loop_counter * sleep_period)} seconds. Try increasing install_via_task_max_poll_counter attribute and re-try."
  end
end