I originally asked this question on StackOverflow, but did not receive any working answers: https://stackoverflow.com/questions/18648713/specify-chef-provider-for-windows-feature.
I'm trying to use Chef (chef-solo) to manage my Windows Server 2008 R2 installation. Chef provides windows_feature
to add roles/features to a Windows server. By default, windows_feature
uses DISM to install roles (if available). However, to my knowledge, not all roles (e.g., RDS-RD-Server) are able to be added via DISM.
I could presumably use Chef::Provider::WindowsFeature::ServerManagerCmd
(identified in the Windows cookbook readme: https://github.com/opscode-cookbooks/windows), but it doesn't look like that is a real class (browsing the source code there). Also, servermanagercmd is deprecated (though it would work).
I wouldn't mind even using a powershell block to add the role, but I'm having a hard time ensuring idempotence. It seems like the not_if
command shell is some weird mingwin shell rather than CMD.
Here's a sample of what I've tried using powershell (doesn't work):
powershell "install_rds_server" do
code %Q{
Import-Module Servermanager
Add-WindowsFeature RDS-RD-Server
}.strip
not_if %Q{
powershell "Import-Module Servermanager; $check = get-windowsfeature -name RDS-RD-Server; if ($check.Installed -ne \"True\") { exit 1 }"
}.strip
end
I've also tried the following:
windows_feature 'RDS-RD-Server' do
provider Chef::Provider::WindowsFeature::ServerManagerCmd
end
which returns the following error:
FATAL: NameError: uninitialized constant Chef::Provider::WindowsFeature::ServerManagerCmd
What would be the recommended Chef way of adding this role?