forked from sous-chefs/iis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sous-chefsGH-476] Feature names translated into powershell format wh…
…en install method is powershell - Using powershell to install features requires passing in a different feature name - To prevent having to do this look up for every windows_feature call I created a wrapper resource that is identical to windows_feature expect it will look up the correct format of the feature to install Signed-off-by: dave-q <24652224+dave-q@users.noreply.github.com>
- Loading branch information
Showing
20 changed files
with
141 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# | ||
# Cookbook:: iis | ||
# Library:: section-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) | ||
features = names | ||
if install_method.to_sym == :windows_feature_powershell | ||
translated_features = [] | ||
names.each do |name| | ||
cmd = "Get-WindowsFeature | Where-Object {$_.AdditionalInfo.InstallName -Eq '#{name}'} | Select -Expand Name" | ||
result = powershell_out cmd | ||
if result.stderr.empty? | ||
translated_features.push(result.stdout.strip) | ||
else | ||
Chef::Log.warn("Unable to translate feature #{name}") | ||
Chef::Log.warn(result.stderr) | ||
translated_features.push(name) | ||
end | ||
end | ||
features = translated_features | ||
end | ||
features | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# | ||
# Cookbook:: iis | ||
# Resource:: install | ||
# | ||
# Copyright:: 2018-2019, 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. | ||
# | ||
|
||
include IISCookbook::WindowsFeatureHelper | ||
|
||
property :feature_name, [Array, String], | ||
description: "The name of the feature(s) or role(s) to install if they differ from the resource block's name. The same feature may have different names depending on the underlying installation method being used (ie DHCPServer vs DHCP; DNS-Server-Full-Role vs DNS).", | ||
name_property: true | ||
|
||
property :source, String, | ||
description: 'Specify a local repository for the feature install.' | ||
|
||
property :all, [true, false], | ||
description: 'Install all sub-features.', | ||
default: false | ||
|
||
property :management_tools, [true, false], | ||
description: 'Install all applicable management tools for the roles, role services, or features (PowerShell-only).', | ||
default: false | ||
|
||
property :install_method, Symbol, | ||
description: 'The underlying installation method to use for feature installation. Specify `:windows_feature_dism` for DISM or `:windows_feature_powershell` for PowerShell.', | ||
equal_to: %i(windows_feature_dism windows_feature_powershell windows_feature_servermanagercmd), | ||
default: :windows_feature_dism | ||
|
||
property :timeout, Integer, | ||
description: 'Specifies a timeout (in seconds) for the feature installation.', | ||
default: 600, | ||
desired_state: false | ||
|
||
action :delete do | ||
feature = transform_feature_name(new_resource.install_method, *new_resource.feature_name) | ||
windows_feature feature do | ||
source new_resource.source | ||
all new_resource.all | ||
management_tools new_resource.management_tools | ||
install_method new_resource.install_method | ||
timeout new_resource.timeout | ||
action :delete | ||
end | ||
end | ||
|
||
action :install do | ||
feature = transform_feature_name(new_resource.install_method, *new_resource.feature_name) | ||
windows_feature feature do | ||
source new_resource.source | ||
all new_resource.all | ||
management_tools new_resource.management_tools | ||
install_method new_resource.install_method | ||
timeout new_resource.timeout | ||
action :install | ||
end | ||
end | ||
|
||
action :remove do | ||
feature = transform_feature_name(new_resource.install_method, *new_resource.feature_name) | ||
windows_feature feature do | ||
source new_resource.source | ||
all new_resource.all | ||
management_tools new_resource.management_tools | ||
install_method new_resource.install_method | ||
timeout new_resource.timeout | ||
action :remove | ||
end | ||
end |