扩展厨师Windows Cookbook … DISM限制

我试图在WinServer 2012上使用Chef来安装.NET 3.5框架。

但是,ms_dotnet35 cookbook不支持WinServer 2012。

所以我复制了它在食谱中使用的代码来安装( 从这里 )(原谅格式):

if platform?('windows') unless File.exists?('C:/Windows/Microsoft.NET/Framework/v3.5') windows_feature 'NetFx3' do action :install end end else Chef::Log.warn('Microsoft Framework .NET 3.5 can only be installed on the Windows platform.') end 

但是,有一个障碍。 当Chef运行时,“windows_feature”传递下面的命令行:

 C:\Windows\sysnative\dism.exe /online /enable-feature /featurename:NetFx3 /norestart 

事实certificate,在WinServer 2012上,您需要传递“/ all”参数,否则您将得到“所需的父function可能未启用”。 exception( 从这里 )

所以现在我正在查看Windows Cookbook中的“windows_feature”的代码( 从这里 ):

 def install_feature(name) # return code 3010 is valid, it indicates a reboot is required shell_out!("#{dism} /online /enable-feature /featurename:#{@new_resource.feature_name} /norestart", {:returns => [0,42,127,3010]}) end 

..我们findDISM的实际呼叫。

推荐的方式是什么? 我应该只是复制shell_out调用,并破解DISM行来得到这个工作?

我是厨师新手,想要遵循最佳实践/正确的范例。 我不明白为什么目前的Windows_feature的实现没有提供一个方法来input像“/所有”的可选参数。

我最终在新的食谱中创建了一个新的配方来处理在Windows server 2012上安装.Net Framework 3.5。

我能够通过从这里下载一个eval ISO来找到所需的文件(因为我没有安装磁盘,我在Azure上)。

装上ISO后,压缩整个.. \ Sources \ sxs文件夹。

我的一个执行命令如下所示:

 execute "install_net35" do command "C:/Windows/sysnative/dism.exe /online /enable-feature /all /featurename:NetFx3 /norestart /limitaccess /source:C:/tempdirectory/sxs" 

…其中“C:/ tempdirectory / sxs”是解压缩的文件。

我还在Windows server 2012的检查中封装了这个执行:

 if win_version.windows_server_2012? || win_version.windows_server_2012_r2? 

..并做一个检查,看看框架是否已经安装(以确保idempotence):

 unless File.exists?('C:/Windows/Microsoft.NET/Framework/v3.5') 

根据文件,我相信你应该能够以下(没有测试 – 所以随时纠正我!)

 if platform?('windows') windows_feature 'NetFx3' do action :install all true end else Chef::Log.warn('Microsoft Framework .NET 3.5 can only be installed on the Windows platform.') end 

https://github.com/opscode-cookbooks/windows

all:布尔值。 可选的。 默认:false。 只有DISM提供者。 强制安装所有依赖项。

除非文件存在是不必要的, windows_feature只能安装,除非安装。