summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-03-21 09:45:49 -0700
committerGitHub <noreply@github.com>2018-03-21 09:45:49 -0700
commitdf092e9c4f7764188c45c881e0ac07771ede4ad6 (patch)
tree132d3cc574f130918e35f56aa264dac27be314b6
parented8e467e421468865ac339ad2d87935f52843dda (diff)
parent14c167b0b014bfcbd351f6ecd53321bf931e69d1 (diff)
downloadchef-df092e9c4f7764188c45c881e0ac07771ede4ad6.tar.gz
Merge pull request #7015 from chef/windows_feature_fix
Support installing removed windows features from source
-rw-r--r--lib/chef/resource/windows_feature_dism.rb20
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/chef/resource/windows_feature_dism.rb b/lib/chef/resource/windows_feature_dism.rb
index 5bbcce4ab0..42eafcf613 100644
--- a/lib/chef/resource/windows_feature_dism.rb
+++ b/lib/chef/resource/windows_feature_dism.rb
@@ -55,9 +55,11 @@ class Chef
unless features_to_install.empty?
message = "install Windows feature#{'s' if features_to_install.count > 1} #{features_to_install.join(',')}"
converge_by(message) do
- addsource = new_resource.source ? "/LimitAccess /Source:\"#{new_resource.source}\"" : ""
- addall = new_resource.all ? "/All" : ""
- shell_out!("dism.exe /online /enable-feature #{features_to_install.map { |f| "/featurename:#{f}" }.join(' ')} /norestart #{addsource} #{addall}", returns: [0, 42, 127, 3010], timeout: new_resource.timeout)
+ install_command = "#{dism} /online /enable-feature #{features_to_install.map { |f| "/featurename:#{f}" }.join(' ')} /norestart"
+ install_command << " /LimitAccess /Source:\"#{new_resource.source}\"" if new_resource.source
+ install_command << " /All" if new_resource.all
+
+ shell_out!(install_command, returns: [0, 42, 127, 3010], timeout: new_resource.timeout)
reload_cached_dism_data # Reload cached dism feature state
end
@@ -104,8 +106,16 @@ class Chef
action_class do
# @return [Array] features the user has requested to install which need installation
def features_to_install
- # the intersection of the features to install & disabled features are what needs installing
- @install ||= new_resource.feature_name & node["dism_features_cache"]["disabled"]
+ @install ||= begin
+ # disabled features are always available to install
+ available_for_install = node["dism_features_cache"]["disabled"]
+
+ # if the user passes a source then removed features are also available for installation
+ available_for_install.concat(node["dism_features_cache"]["removed"]) if new_resource.source
+
+ # the intersection of the features to install & disabled/removed(if passing source) features are what needs installing
+ new_resource.feature_name & available_for_install
+ end
end
# @return [Array] features the user has requested to remove which need removing