Question

I'm attempting to install .NET 3.5 framework on WinServer 2012, using Chef.

The ms_dotnet35 cookbook however, doesn't support WinServer 2012.

So I've copied the code it uses in the cookbook to install (from here) (pardon the formatting):

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

However, there is a snag. When Chef runs, "windows_feature" passes the following commandline:

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

It turns out that on WinServer 2012, you need to pass the "/all" argument or you'll get an "A required parent feature may not be enabled." exception (from here)

So now I am looking at the code for "windows_feature" in the windows cookbook (from here):

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

..where we find the actual call to DISM.

What is the recommended way for me to extend this? Should I just copy the shell_out call and hack the DISM line to get this to work?

I'm new to Chef and want to be following the best practice/correct paradigm. I don't understand why the current implementation of windows_feature doesn't provide a way to enter optional arguments like "/all".

Was it helpful?

Solution

I ended up creating a new recipe in a new cookbook to handle installing .Net Framework 3.5 on Windows Server 2012.

I was able to find the needed files (since I don't have an install disk, I'm on Azure) by dowloading an eval ISO from here.

After mounting the ISO I zipped the entire ..\Sources\sxs folder.

my one execute command looks like this:

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

...where "C:/tempdirectory/sxs" is the unzipped file.

I also wrapped the execution in a check for Windows Server 2012:

if win_version.windows_server_2012? || win_version.windows_server_2012_r2?

..and do a check to see if the framework is already installed (to ensure idempotence):

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

OTHER TIPS

According to the documentation I believe you should be able to the following (haven't tested it - so feel free to correct me!)

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: Boolean. Optional. Default: false. DISM provider only. Forces all dependencies to be installed.

The unless file exists isn't necessary, windows_feature only installs unless installed anyway.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top