Thursday, 5 September 2013

Specify Chef provider for windows_feature

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.
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
What would be the recommended Chef way of adding this role?

No comments:

Post a Comment