Sql server 2012 由chef客户端运行时,DISM/SQL2012无法访问Windows Update

Sql server 2012 由chef客户端运行时,DISM/SQL2012无法访问Windows Update,sql-server-2012,chef-infra,windows-server-2012,winrm,Sql Server 2012,Chef Infra,Windows Server 2012,Winrm,我的问题是:当通过WinRM运行chef时,是否存在某种不允许程序进入internet的权限问题 我正在尝试使用Server 2012 Std上的Chef 11.4.4来部署SQL 2012 Std。我遇到了两个问题,我相信它们是相关的: windows_feature "NetFx3" do action :install end 这失败了,因为DISM应该转到microsoft update并下载.Net 3.5.1文件。如果我通过RDP手动运行DISM/online/enable-f

我的问题是:当通过WinRM运行chef时,是否存在某种不允许程序进入internet的权限问题

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

windows_feature "NetFx3" do
  action :install
end
这失败了,因为DISM应该转到microsoft update并下载.Net 3.5.1文件。如果我通过RDP手动运行
DISM/online/enable-feature/featurename:NetFx3/norestart
,它工作得很好-这基本上就是windows_功能的运行方式

如果我通过一个配方运行DISM/online/enable feature/featurename:NetFx3/norestart/LimitAccess/Source:d:\sources\sxs(带DVD),它会工作。实际上,这绕过了在线下载文件的需要

第二个问题是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

我通过winrm 192.168.170.145“chef client-c:/chef/client.rb'-m-x nfox运行chef。当我从administrator:cmd窗口运行
chef client
时,我没有这个问题。

是的,与您在本地执行命令相比,winrm(chef的通信协议)没有完整的用户“上下文”(即使是以本地管理员特权用户或本地管理员的身份执行命令)

前面提到的解决方案是使用计划任务,这些任务在机器上异步启动。这样做的好处是具有完整的上下文,但缺点是您需要知道计划任务何时完成才能删除它并继续。至于使用计划任务,您应该使用带有lwrp的windows cookbook

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

  • 捕获错误(仅在第一次运行 配方;在功能安装后运行不会抛出错误)和 在预定的任务中处理它;chef中的错误处理是一个漫长的过程 主题,但简而言之,您只能在 chef运行的“编译”阶段,这就是end.run\u操作( :安装)正在进行)
  • 创建并运行计划任务
  • 轮询,直到功能安装完毕或超过超时
  • 无论功能安装成功与否,始终删除任务
  • 根据成功/失败的功能安装继续
创建包含以下内容的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

简短回答:是的,WinRM在网络访问方面有一些限制,但通常我们会被网络共享访问所困扰,我们的想法是使用CredSSP。规避winrm限制的常用方法是将chef配置为计划任务,并使用
winrm…”启动此计划任务的运行schtasks/Run/TN'
终于找到了命令行参数,该选项是通过
winrs
启动chef客户端,并附加
-authentication:CredSSP
参数,在远程目标上配置CredSSP,这听起来很疯狂。。。最好以幂等方式进行安装,并让chef从sched-taks(定期或不定期)运行,但创建多个sched任务显然是在寻找问题……只创建、运行和删除一个计划任务(无论成功与否)。这与配置管理系统第一次执行上述操作时要执行的幂等行为(即,您无法确定最后的系统状态)相去甚远。它将抛出异常,该异常将被捕获,并通过windows_任务安装功能。此后(如果上面一次又一次地运行),将不会抛出异常,因为该功能已安装。实现了幂等性。不,因为您假设计划的任务将成功,所以无法保证安装确实完成。。。