3

我的问题是:通过 WinRM 运行 Chef 时是否存在某种权限问题,不允许程序访问 Internet?

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

windows_feature "NetFx3" do
  action :install
end

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

如果我DISM /online /enable-feature /featurename:NetFx3 /norestart /LimitAccess /Source:d:\sources\sxs浏览一个食谱(带有 DVD),它就可以工作。实际上,这绕过了在线下载文件的需要。

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

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 窗口。

4

1 回答 1

0

是的,与您在本地执行命令(即使作为本地管理员权限用户或本地管理员执行此操作)相比,winrm(厨师的通信协议)没有完整的用户“上下文”。

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

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

  • 捕获错误(这只会在配方的第一次运行时发生;在安装功能后运行不会抛出错误)并在计划任务中处理它;Chef 中的错误处理是一个冗长的话题,但简而言之,您只能在 Chef 运行的“编译”阶段捕获 Chef 错误,这就是 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
于 2015-10-31T06:22:40.733 回答