Skip to content

Commit

Permalink
[sous-chefsGH-476] Allow specifying install method for internal windo…
Browse files Browse the repository at this point in the history
…ws_feature resources

- Introduces new attribute ['iis']['windows_feature_install_method']
the value of this vode is passed to any calls to the windows_feature resource
as the resources install_method property

- feature names are translated into powershell format when install
method is powershell

  - Using powershell to install features requires passing in a
    different feature name
  - added library method to translate any feature names into the powershell
    format if the install mode is powershell
  - the look up handles the scenario where someone has already
    provided the feature name in the powershell format

Signed-off-by: dave-q <24652224+dave-q@users.noreply.github.com>
  • Loading branch information
dave-q committed Apr 12, 2021
1 parent ec7dd3c commit c83912c
Show file tree
Hide file tree
Showing 28 changed files with 184 additions and 17 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ jobs:
- 'section'
- 'site'
- 'vdir'
- 'default-windowsfeatures-powershell'
fail-fast: false

steps:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ This file is used to list changes made in each version of the iis cookbook.

## Unreleased

- Allow specifying install method for windows_feature resources

## 7.5.1 - *2021-03-25*

- Cookstyle fixes
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ This cookbook is maintained by the Sous Chefs. The Sous Chefs are a community of
- `node['iis']['pubroot']` - . default is `%SYSTEMDRIVE%\inetpub`
- `node['iis']['docroot']` - IIS web site home directory. default is `%SYSTEMDRIVE%\inetpub\wwwroot`
- `node['iis']['cache_dir']` - location of cached data. default is `%SYSTEMDRIVE%\inetpub\temp`
- `node['iis']['windows_feature_install_method']` - specify the install method that will be used by any windows_feature resources. If ommitted it will not be specified and will the windows_feature supply a default. Valid options are ':windows_feature_dism, :windows_feature_powershell, :windows_feature_servermanagercmd'. Default is :windows_feature_dism

## Resources

Expand Down
2 changes: 2 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@
default['iis']['source'] = nil

default['iis']['recycle']['log_events'] = 'Time, Requests, Schedule, Memory, IsapiUnhealthy, OnDemand, ConfigChange, PrivateMemory'

default['iis']['windows_feature_install_method'] = :windows_feature_dism
1 change: 1 addition & 0 deletions documentation/iis_install.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Simple resource to install the IIS feature
| ----------------------- | -------- | -------- | ------------------------------------ |
| `source` | String | No | Source to install the features from. |
| `additional_components` | Array | No | Features of IIS to install |
| `install_method` | :windows_feature_dism, :windows_feature_powershell | No | install_method to be used to any windows_features resources. Default is :windows_feature_dism |

## Examples

Expand Down
1 change: 1 addition & 0 deletions documentation/iis_manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Configures the IIS Manager service
| `enable_remote_management` | true, false | `true` | If remote access allowed |
| `log_directory` | String | | Optional. The directory to write log files to |
| `port` | Integer | `8172` | The port the service listens on. |
| `install_method` | :windows_feature_dism, :windows_feature_powershell, :windows_feature_servermanagercmd | `:windows_feature_dism` | Optional. install_method to be used to any windows_features resources |

## Examples

Expand Down
6 changes: 6 additions & 0 deletions kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,9 @@ suites:
- name: vdir
run_list:
- recipe[test::vdir]
- name: default-windowsfeatures-powershell
run_list:
- recipe[iis::default]
attributes:
iis:
windows_feature_install_method: windows_feature_powershell
40 changes: 40 additions & 0 deletions libraries/windowsfeature_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#
# Cookbook:: iis
# Library:: windowsfeature_helper
#
# Copyright:: 2017-2021, Chef Software, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

module IISCookbook
module WindowsFeatureHelper
def transform_feature_name(install_method, names)
if install_method.to_sym == :windows_feature_powershell
Array(names).map do |name|
cmd = "Get-WindowsFeature | Where-Object {$_.AdditionalInfo.InstallName -Eq '#{name}' -or $_.Name -eq '#{name}'} | Select -Expand Name"
result = powershell_out cmd
if result.stderr.empty?
next result.stdout.strip
else
Chef::Log.warn("Unable to translate feature #{name}")
Chef::Log.warn(result.stderr)
next name
end
end
else
names
end
end
end
end
1 change: 1 addition & 0 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
iis_install 'install IIS' do
additional_components node['iis']['components']
source node['iis']['source']
install_method node['iis']['windows_feature_install_method']&.to_sym
end

service 'iis' do
Expand Down
7 changes: 6 additions & 1 deletion recipes/mod_application_initialization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
# limitations under the License.
#

include IISCookbook::WindowsFeatureHelper

include_recipe 'iis'
install_method = node['iis']['windows_feature_install_method']&.to_sym

windows_feature 'IIS-ApplicationInit'
windows_feature transform_feature_name(install_method, 'IIS-ApplicationInit') do
install_method install_method
end
7 changes: 6 additions & 1 deletion recipes/mod_aspnet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@
# limitations under the License.
#

include IISCookbook::WindowsFeatureHelper

include_recipe 'iis'
include_recipe 'iis::mod_isapi'

windows_feature %w(IIS-NetFxExtensibility IIS-ASPNET) do
install_method = node['iis']['windows_feature_install_method']&.to_sym

windows_feature transform_feature_name(install_method, %w(IIS-NetFxExtensibility IIS-ASPNET)) do
action :install
all !IISCookbook::Helper.older_than_windows2012?
source node['iis']['source'] unless node['iis']['source'].nil?
install_method install_method
end
8 changes: 7 additions & 1 deletion recipes/mod_aspnet45.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@
# limitations under the License.
#

include IISCookbook::WindowsFeatureHelper

include_recipe 'iis'
include_recipe 'iis::mod_isapi'

windows_feature %w(NetFx4Extended-ASPNET45 IIS-NetFxExtensibility45 IIS-ASPNET45)
install_method = node['iis']['windows_feature_install_method']&.to_sym

windows_feature transform_feature_name(install_method, %w(NetFx4Extended-ASPNET45 IIS-NetFxExtensibility45 IIS-ASPNET45)) do
install_method install_method
end
8 changes: 7 additions & 1 deletion recipes/mod_auth_basic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@
# limitations under the License.
#

include IISCookbook::WindowsFeatureHelper

include_recipe 'iis'

windows_feature 'IIS-BasicAuthentication'
install_method = node['iis']['windows_feature_install_method']&.to_sym

windows_feature transform_feature_name(install_method, 'IIS-BasicAuthentication') do
install_method install_method
end

iis_section 'unlocks basic authentication control in web.config' do
section 'system.webServer/security/authentication/basicAuthentication'
Expand Down
8 changes: 7 additions & 1 deletion recipes/mod_auth_digest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@
# limitations under the License.
#

include IISCookbook::WindowsFeatureHelper

include_recipe 'iis'

windows_feature 'IIS-DigestAuthentication'
install_method = node['iis']['windows_feature_install_method']&.to_sym

windows_feature transform_feature_name(install_method, 'IIS-DigestAuthentication') do
install_method install_method
end

iis_section 'unlocks digest authentication control in web.config' do
section 'system.webServer/security/authentication/digestAuthentication'
Expand Down
8 changes: 7 additions & 1 deletion recipes/mod_auth_windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@
# limitations under the License.
#

include IISCookbook::WindowsFeatureHelper

include_recipe 'iis'

windows_feature 'IIS-WindowsAuthentication'
install_method = node['iis']['windows_feature_install_method']&.to_sym

windows_feature transform_feature_name(install_method, 'IIS-WindowsAuthentication') do
install_method install_method
end

iis_section 'unlocks windows authentication control in web.config' do
section 'system.webServer/security/authentication/windowsAuthentication'
Expand Down
8 changes: 7 additions & 1 deletion recipes/mod_cgi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
# limitations under the License.
#

include IISCookbook::WindowsFeatureHelper

include_recipe 'iis'

windows_feature 'IIS-CGI'
install_method = node['iis']['windows_feature_install_method']&.to_sym

windows_feature transform_feature_name(install_method, 'IIS-CGI') do
install_method install_method
end
8 changes: 7 additions & 1 deletion recipes/mod_compress_dynamic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
# limitations under the License.
#

include IISCookbook::WindowsFeatureHelper

include_recipe 'iis'

windows_feature 'IIS-HttpCompressionDynamic'
install_method = node['iis']['windows_feature_install_method']&.to_sym

windows_feature transform_feature_name(install_method, 'IIS-HttpCompressionDynamic') do
install_method install_method
end
8 changes: 7 additions & 1 deletion recipes/mod_compress_static.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
# limitations under the License.
#

include IISCookbook::WindowsFeatureHelper

include_recipe 'iis'

windows_feature 'IIS-HttpCompressionStatic'
install_method = node['iis']['windows_feature_install_method']&.to_sym

windows_feature transform_feature_name(install_method, 'IIS-HttpCompressionStatic') do
install_method install_method
end
8 changes: 7 additions & 1 deletion recipes/mod_ftp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
# limitations under the License.
#

include IISCookbook::WindowsFeatureHelper

include_recipe 'iis'

windows_feature %w(IIS-FTPServer IIS-FTPSvc IIS-FTPExtensibility)
install_method = node['iis']['windows_feature_install_method']&.to_sym

windows_feature transform_feature_name(install_method, %w(IIS-FTPServer IIS-FTPSvc IIS-FTPExtensibility)) do
install_method install_method
end
8 changes: 7 additions & 1 deletion recipes/mod_iis6_metabase_compat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
# limitations under the License.
#

include IISCookbook::WindowsFeatureHelper

include_recipe 'iis'

windows_feature %w(IIS-IIS6ManagementCompatibility IIS-Metabase)
install_method = node['iis']['windows_feature_install_method']&.to_sym

windows_feature transform_feature_name(install_method, %w(IIS-IIS6ManagementCompatibility IIS-Metabase)) do
install_method install_method
end
8 changes: 7 additions & 1 deletion recipes/mod_isapi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
# limitations under the License.
#

include IISCookbook::WindowsFeatureHelper

include_recipe 'iis'

windows_feature %w(IIS-ISAPIFilter IIS-ISAPIExtensions)
install_method = node['iis']['windows_feature_install_method']&.to_sym

windows_feature transform_feature_name(install_method, %w(IIS-ISAPIFilter IIS-ISAPIExtensions)) do
install_method install_method
end
8 changes: 7 additions & 1 deletion recipes/mod_logging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
# limitations under the License.
#

include IISCookbook::WindowsFeatureHelper

include_recipe 'iis'

windows_feature 'IIS-CustomLogging'
install_method = node['iis']['windows_feature_install_method']&.to_sym

windows_feature transform_feature_name(install_method, 'IIS-CustomLogging') do
install_method install_method
end
7 changes: 6 additions & 1 deletion recipes/mod_management.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@
# limitations under the License.
#

include IISCookbook::WindowsFeatureHelper

include_recipe 'iis'

windows_feature %w(IIS-ManagementConsole IIS-ManagementService) do
install_method = node['iis']['windows_feature_install_method']&.to_sym

windows_feature transform_feature_name(install_method, %w(IIS-ManagementConsole IIS-ManagementService)) do
action :install
all !IISCookbook::Helper.older_than_windows2012?
install_method install_method
end
8 changes: 7 additions & 1 deletion recipes/mod_security.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
# limitations under the License.
#

include IISCookbook::WindowsFeatureHelper

include_recipe 'iis'

windows_feature %w(IIS-URLAuthorization IIS-RequestFiltering IIS-IPSecurity)
install_method = node['iis']['windows_feature_install_method']&.to_sym

windows_feature transform_feature_name(install_method, %w(IIS-URLAuthorization IIS-RequestFiltering IIS-IPSecurity)) do
install_method install_method
end
8 changes: 7 additions & 1 deletion recipes/mod_tracing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
# limitations under the License.
#

include IISCookbook::WindowsFeatureHelper

include_recipe 'iis'

windows_feature 'IIS-HttpTracing'
install_method = node['iis']['windows_feature_install_method']&.to_sym

windows_feature transform_feature_name(install_method, 'IIS-HttpTracing') do
install_method install_method
end
5 changes: 4 additions & 1 deletion resources/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,20 @@
#

include IISCookbook::Helper
include IISCookbook::WindowsFeatureHelper

property :source, String
property :additional_components, Array, default: []
property :install_method, Symbol, required: false, equal_to: [:windows_feature_dism, :windows_feature_powershell, :windows_feature_servermanagercmd], default: :windows_feature_dism

action :install do
features_to_install = ['IIS-WebServerRole'].concat new_resource.additional_components
features_to_install = transform_feature_name(new_resource.install_method, ['IIS-WebServerRole'].concat(new_resource.additional_components))

windows_feature 'Install IIS and additional components' do
feature_name features_to_install
action :install
all !IISCookbook::Helper.older_than_windows2012?
source new_resource.source unless new_resource.source.nil?
install_method new_resource.install_method
end
end
2 changes: 2 additions & 0 deletions resources/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
property :enable_remote_management, [true, false], default: true
property :log_directory, String
property :port, Integer, default: 8172
property :install_method, Symbol, required: false, equal_to: [:windows_feature_dism, :windows_feature_powershell, :windows_feature_servermanagercmd], default: :windows_feature_dism

action :config do
iis_install 'Web-Mgmt-Service' do
additional_components ['IIS-ManagementService']
install_method new_resource.install_method
end

# properties stored in the registry
Expand Down
14 changes: 14 additions & 0 deletions spec/unit/recipes/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,18 @@
expect(chef_run).to start_service('iis').with(service_name: 'W3SVC')
end
end

[:windows_feature_dism, :windows_feature_powershell, :windows_feature_servermanagercmd].each do |method|
context "When iis windows feature install method is provided as #{method}, on a unspecified platform" do
let(:chef_run) do
ChefSpec::SoloRunner.new do |node|
node.override['iis']['windows_feature_install_method'] = method
end.converge(described_recipe)
end

it "installs windows features using #{method}" do
expect(chef_run).to install_iis_install('install IIS').with(install_method: method)
end
end
end
end

0 comments on commit c83912c

Please sign in to comment.