无法使用 Chef Test Kitchen 在 Windows Server 2012 R2 上安装 .NET 3.5

Cannot install .NET 3.5 on Windows Server 2012 R2 with Chef Test Kitchen

我找不到在 Windows Server 2012 R2 上使用 Chef Test Kitchen 安装 .NET 3.5 的方法。

我可以使用

从命令行安装框架

C:\Windows\system32\dism.exe /online /enable-feature /featurename:NetFx3 /norestart /All /source:"C:\Users\admin\AppData\Local\Temp\dotnetfx35.exe"

或从 PowerShell 提示

Install-WindowsFeature –name NET-Framework-Core –source "C:\Users\admin\AppData\Local\Temp\dotnetfx35.exe"

但是如果我在 chef 中执行以下任一操作,我会得到同样的错误:

Deployment Image Servicing and Management tool

Version: 6.3.9600.17031

Image Version: 6.3.9600.17031

Enabling feature(s)

Error: 0x800f0906

The source files could not be downloaded.

Use the "source" option to specify the location of the files that are required to restore the feature. For more information on specifying a source location, see http://go.microsoft.com/fwlink....

我已将 dotnetfx35.exe 复制到用户的临时目录 C:\Users\admin\AppData\Local\Temp\dotnetfx35.exe

主厨--版本

Chef Development Kit Version: 0.15.16

chef-client version: 12.11.18

delivery version: master (444effdf9c81908795e88157f01cd667a6c43b5f)

berks version: 4.3.5 kitchen version: 1.7.3

目前我尝试过的资源:

使用 Chocolatey:

chocolatey_package 'dotnet3.5' do
  options "--allow-empty-checksums --ignore-package-exit-codes"
end

执行:

  execute 'install_dot_net_3-5' do
    command "C:\Windows\system32\dism.exe /online /enable-feature /featurename:NetFx3 /norestart /All /source:\"C:\Users\admin\AppData\Local\Temp\dotnetfx35.exe\""
    timeout 9999
  end

批量:

  batch 'install_dot_net_3-5' do
    code <<-EOH
      C:\Windows\system32\dism.exe /online /enable-feature /featurename:NetFx3 /norestart /All /source:"C:\Users\admin\AppData\Local\Temp\dotnetfx35.exe"
    EOH
    cwd "#{ENV['TEMP']}"
    timeout 9999
  end

Powershell 脚本:

  powershell_script 'install_dot_net_3-5' do
    code <<-EOH
      Install-WindowsFeature –name NET-Framework-Core –source "C:\Users\admin\AppData\Local\Temp\dotnetfx35.exe"
    EOH
  end

非常感谢 Chef 的 Matt Wrock 给我答案:

If you are trying to install .net 3.5 via test kitchen, use the elevated winrm transport. This will allow .net 3.5 to be accessed via windows update without the need for pointing at a source file. Remove the source argument from your dism command and add this to your .kitchen.yml:

transport:
  name: winrm
  elevated: true

elevated: true 添加到 .kitchen.yml 文件后,我已在 Test Kitchen 的 Windows Server 2012 R2 上成功安装了 .NET 3.5,配方中包含以下代码。相同的配方在生产箱的 Chef Client 中有效。

  powershell_script 'install_dot_net_3-5' do
    code <<-EOH
      Install-WindowsFeature -name NET-Framework-Core
    EOH
  end