Chef Windows Installing Roles

While using Chef for Windows, there are multiple backends for the Windows feature resourceDISM and servermanagercmd. Each one has a specific Ruby class that will be used based on the determined backend as follows:

  • Chef::Provider::WindowsFeature::DISM: This uses DISM to manage roles/features (default unless DISM is not present)
  • Chef::Provider::WindowsFeature::ServerManagerCmd: This uses Server Manager to manage roles/features (the fallback provider when DISM is absent)

Examples of using features and roles

Enable the printer service role (Printing-Server-Role) as shown in the following example output from DISM:

windows_feature "Printing-Service-Role" do
 action :install

Since you can use arbitrary Ruby code inside your recipes, you can perform an operation on multiple components with ease. For example, to remove both the fax server and the printing server, you could use the following code:

to_remove = ["Printing-Service-Role", "FaxServiceRole"]
to_remove.each do |feat|
 windows_feature feat do
 action :remove

In order to enable IIS on a system where DISM is not available, you would need to use the role name as output using servermanagercmd as follows:

windows_feature "AS-Web-Support" do  action :install end