chef 17.2.29 → 17.3.48

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -3
  3. data/chef.gemspec +1 -0
  4. data/lib/chef/client.rb +1 -1
  5. data/lib/chef/data_bag.rb +1 -2
  6. data/lib/chef/data_bag_item.rb +1 -2
  7. data/lib/chef/deprecated.rb +10 -4
  8. data/lib/chef/dsl.rb +1 -0
  9. data/lib/chef/dsl/render_helpers.rb +44 -0
  10. data/lib/chef/dsl/secret.rb +64 -0
  11. data/lib/chef/dsl/toml.rb +116 -0
  12. data/lib/chef/dsl/universal.rb +5 -0
  13. data/lib/chef/exceptions.rb +22 -0
  14. data/lib/chef/handler/slow_report.rb +1 -1
  15. data/lib/chef/json_compat.rb +1 -1
  16. data/lib/chef/policy_builder/policyfile.rb +88 -45
  17. data/lib/chef/provider/file.rb +2 -2
  18. data/lib/chef/provider/lwrp_base.rb +1 -1
  19. data/lib/chef/provider/package/habitat.rb +168 -0
  20. data/lib/chef/provider/package/powershell.rb +5 -0
  21. data/lib/chef/providers.rb +1 -0
  22. data/lib/chef/resource/chef_client_config.rb +7 -2
  23. data/lib/chef/resource/chef_client_cron.rb +1 -1
  24. data/lib/chef/resource/chef_client_launchd.rb +1 -1
  25. data/lib/chef/resource/chef_client_scheduled_task.rb +1 -1
  26. data/lib/chef/resource/chef_client_systemd_timer.rb +1 -1
  27. data/lib/chef/resource/chef_client_trusted_certificate.rb +2 -2
  28. data/lib/chef/resource/chef_vault_secret.rb +2 -2
  29. data/lib/chef/resource/dsc_resource.rb +1 -1
  30. data/lib/chef/resource/execute.rb +3 -3
  31. data/lib/chef/resource/gem_package.rb +2 -1
  32. data/lib/chef/resource/habitat/_habitat_shared.rb +28 -0
  33. data/lib/chef/resource/habitat/habitat_package.rb +129 -0
  34. data/lib/chef/resource/habitat/habitat_sup.rb +329 -0
  35. data/lib/chef/resource/habitat/habitat_sup_systemd.rb +67 -0
  36. data/lib/chef/resource/habitat/habitat_sup_windows.rb +90 -0
  37. data/lib/chef/resource/habitat_config.rb +107 -0
  38. data/lib/chef/resource/habitat_install.rb +247 -0
  39. data/lib/chef/resource/habitat_service.rb +451 -0
  40. data/lib/chef/resource/habitat_user_toml.rb +92 -0
  41. data/lib/chef/resource/lwrp_base.rb +1 -1
  42. data/lib/chef/resource/support/HabService.dll.config.erb +19 -0
  43. data/lib/chef/resource/support/client.erb +8 -1
  44. data/lib/chef/resource/support/sup.toml.erb +179 -0
  45. data/lib/chef/resource/windows_defender.rb +163 -0
  46. data/lib/chef/resource/windows_defender_exclusion.rb +125 -0
  47. data/lib/chef/resource/windows_printer.rb +78 -44
  48. data/lib/chef/resource/windows_printer_port.rb +1 -1
  49. data/lib/chef/resource/windows_update_settings.rb +259 -0
  50. data/lib/chef/resources.rb +12 -1
  51. data/lib/chef/secret_fetcher.rb +54 -0
  52. data/lib/chef/secret_fetcher/aws_secrets_manager.rb +53 -0
  53. data/lib/chef/secret_fetcher/azure_key_vault.rb +56 -0
  54. data/lib/chef/secret_fetcher/base.rb +72 -0
  55. data/lib/chef/secret_fetcher/example.rb +46 -0
  56. data/lib/chef/version.rb +1 -1
  57. data/spec/functional/mixin/from_file_spec.rb +1 -1
  58. data/spec/integration/recipes/recipe_dsl_spec.rb +1 -1
  59. data/spec/integration/recipes/resource_action_spec.rb +4 -4
  60. data/spec/support/shared/unit/provider/file.rb +2 -8
  61. data/spec/unit/data_bag_item_spec.rb +2 -2
  62. data/spec/unit/data_bag_spec.rb +1 -1
  63. data/spec/unit/dsl/render_helpers_spec.rb +102 -0
  64. data/spec/unit/dsl/secret_spec.rb +65 -0
  65. data/spec/unit/policy_builder/dynamic_spec.rb +0 -5
  66. data/spec/unit/policy_builder/policyfile_spec.rb +144 -56
  67. data/spec/unit/provider/apt_update_spec.rb +3 -1
  68. data/spec/unit/provider/mount/aix_spec.rb +1 -1
  69. data/spec/unit/provider/package/powershell_spec.rb +74 -12
  70. data/spec/unit/resource/windows_defender_exclusion_spec.rb +62 -0
  71. data/spec/unit/resource/windows_defender_spec.rb +71 -0
  72. data/spec/unit/resource/windows_update_settings_spec.rb +64 -0
  73. data/spec/unit/secret_fetcher/azure_key_vault_spec.rb +63 -0
  74. data/spec/unit/secret_fetcher_spec.rb +82 -0
  75. metadata +51 -7
@@ -0,0 +1,125 @@
1
+ #
2
+ # Copyright:: Chef Software, Inc.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require_relative "../resource"
18
+
19
+ class Chef
20
+ class Resource
21
+ class WindowsDefenderExclusion < Chef::Resource
22
+
23
+ provides :windows_defender_exclusion
24
+
25
+ description "Use the **windows_defender_exclusion** resource to exclude paths, processes, or file types from Windows Defender realtime protection scanning."
26
+ introduced "17.3"
27
+ examples <<~DOC
28
+ **Add excluded items to Windows Defender scans**:
29
+
30
+ ```ruby
31
+ windows_defender_exclusion 'Add to things to be excluded from scanning' do
32
+ paths 'c:\\foo\\bar, d:\\bar\\baz'
33
+ extensions 'png, foo, ppt, doc'
34
+ process_paths 'c:\\windows\\system32'
35
+ action :add
36
+ end
37
+ ```
38
+
39
+ **Remove excluded items from Windows Defender scans**:
40
+
41
+ ```ruby
42
+ windows_defender_exclusion 'Remove things from the list to be excluded' do
43
+ process_paths 'c:\\windows\\system32'
44
+ action :remove
45
+ end
46
+ ```
47
+ DOC
48
+ unified_mode true
49
+
50
+ property :paths, [String, Array], default: [],
51
+ coerce: proc { |x| to_consistent_path_array(x) },
52
+ description: "File or directory paths to exclude from scanning."
53
+
54
+ property :extensions, [String, Array], default: [],
55
+ coerce: proc { |x| to_consistent_path_array(x) },
56
+ description: "File extensions to exclude from scanning."
57
+
58
+ property :process_paths, [String, Array], default: [],
59
+ coerce: proc { |x| to_consistent_path_array(x) },
60
+ description: "Paths to executables to exclude from scanning."
61
+
62
+ def to_consistent_path_array(x)
63
+ fixed = x.dup || []
64
+ fixed = fixed.split(/\s*,\s*/) if fixed.is_a?(String)
65
+ fixed.map!(&:downcase)
66
+ fixed.map! { |v| v.gsub(%r{/}, "\\") }
67
+ fixed
68
+ end
69
+
70
+ load_current_value do |new_resource|
71
+ Chef::Log.debug("Running 'Get-MpPreference | Select-Object ExclusionExtension,ExclusionPath,ExclusionProcess' to get Windows Defender State")
72
+
73
+ values = powershell_exec!("Get-MPpreference | Select-Object ExclusionExtension,ExclusionPath,ExclusionProcess").result
74
+
75
+ values.transform_values! { |x| Array(x) }
76
+
77
+ paths new_resource.paths & values["ExclusionPath"]
78
+ extensions new_resource.extensions & values["ExclusionExtension"]
79
+ process_paths new_resource.process_paths & values["ExclusionProcess"]
80
+ end
81
+
82
+ action :add, description: "Add an exclusion to Windows Defender." do
83
+ converge_if_changed do
84
+ powershell_exec!(add_cmd)
85
+ end
86
+ end
87
+
88
+ action :remove, description: "Remove an exclusion to Windows Defender." do
89
+ converge_if_changed do
90
+ powershell_exec!(remove_cmd)
91
+ end
92
+ end
93
+
94
+ action_class do
95
+ MAPPING = {
96
+ paths: "ExclusionPath",
97
+ extensions: "ExclusionExtension",
98
+ process_paths: "ExclusionProcess",
99
+ }.freeze
100
+
101
+ def add_cmd
102
+ cmd = "Add-MpPreference -Force"
103
+
104
+ MAPPING.each do |prop, flag|
105
+ to_add = new_resource.send(prop) - current_resource.send(prop)
106
+ cmd << " -#{flag} #{to_add.join(",")}" unless to_add.empty?
107
+ end
108
+
109
+ cmd
110
+ end
111
+
112
+ def remove_cmd
113
+ cmd = "Remove-MpPreference -Force"
114
+
115
+ MAPPING.each do |prop, flag|
116
+ to_add = new_resource.send(prop) & current_resource.send(prop)
117
+ cmd << " -#{flag} #{to_add.join(",")}" unless to_add.empty?
118
+ end
119
+
120
+ cmd
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
@@ -22,6 +22,10 @@ require_relative "../resource"
22
22
 
23
23
  class Chef
24
24
  class Resource
25
+ # @todo
26
+ # 1. Allow updating the printer properties
27
+ # 2. Fail with a warning if the port can't be found and create_port is false
28
+ # 3. Fail with helpful messaging if the printer driver can't be installed
25
29
  class WindowsPrinter < Chef::Resource
26
30
  unified_mode true
27
31
 
@@ -29,7 +33,7 @@ class Chef
29
33
 
30
34
  provides(:windows_printer) { true }
31
35
 
32
- description "Use the **windows_printer** resource to setup Windows printers. Note that this doesn't currently install a printer driver. You must already have the driver installed on the system."
36
+ description "Use the **windows_printer** resource to setup Windows printers. This resource will automatically install the driver specified in the `driver_name` property and will automatically create a printer port using either the `ipv4_address` property or the `port_name property."
33
37
  introduced "14.0"
34
38
  examples <<~DOC
35
39
  **Create a printer**:
@@ -50,6 +54,23 @@ class Chef
50
54
  action :delete
51
55
  end
52
56
  ```
57
+
58
+ **Create a printer port and a printer that uses that port (new in 17.3)**
59
+
60
+ ```ruby
61
+ windows_printer_port '10.4.64.39' do
62
+ port_name 'My awesome printer port'
63
+ snmp_enabled true
64
+ port_protocol 2
65
+ end
66
+
67
+ windows_printer 'HP LaserJet 5th Floor' do
68
+ driver_name 'HP LaserJet 4100 Series PCL6'
69
+ port_name 'My awesome printer port'
70
+ ipv4_address '10.4.64.38'
71
+ create_port false
72
+ end
73
+ ```
53
74
  DOC
54
75
 
55
76
  property :device_id, String,
@@ -84,25 +105,74 @@ class Chef
84
105
  proc { |v| v.match(Resolv::IPv4::Regex) },
85
106
  }
86
107
 
87
- PRINTERS_REG_KEY = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\\'.freeze unless defined?(PRINTERS_REG_KEY)
108
+ property :create_port, [TrueClass, FalseClass],
109
+ description: "Create a printer port for the printer. Set this to false and specify the `port_name` property if using the `windows_printer_port` resource to create the port instead.",
110
+ introduced: "17.3",
111
+ default: true, desired_state: false
112
+
113
+ property :port_name, String,
114
+ description: "The port name.",
115
+ default: lazy { |x| "IP_#{x.ipv4_address}" },
116
+ introduced: "17.3",
117
+ default_description: "The resource block name or the ipv4_address prepended with IP_."
88
118
 
89
- # @todo Set @current_resource printer properties from registry
90
119
  load_current_value do |new_resource|
91
- name new_resource.name
120
+ printer_data = powershell_exec(%Q{Get-WmiObject -Class Win32_Printer -Filter "Name='#{new_resource.device_id}'"}).result
121
+
122
+ if printer_data.empty?
123
+ current_value_does_not_exist!
124
+ else
125
+ device_id new_resource.device_id
126
+ comment printer_data["Comment"]
127
+ default printer_data["Default"]
128
+ location printer_data["Location"]
129
+ shared printer_data["Shared"]
130
+ share_name printer_data["ShareName"]
131
+ port_name printer_data["PortName"]
132
+
133
+ driver_data = powershell_exec(%Q{Get-PrinterDriver -Name="#{new_resource.driver_name}"}).result
134
+ unless driver_data.empty?
135
+ driver_name new_resource.driver_name
136
+ end
137
+ end
92
138
  end
93
139
 
94
140
  action :create, description: "Create a new printer and printer port, if one doesn't already." do
95
- if printer_exists?
141
+ if current_resource
96
142
  Chef::Log.info "#{@new_resource} already exists - nothing to do."
97
143
  else
98
- converge_by("Create #{@new_resource}") do
99
- create_printer
144
+ # Create the printer port first unless the property is set to false
145
+ if new_resource.create_port
146
+ windows_printer_port new_resource.port_name do
147
+ ipv4_address new_resource.ipv4_address
148
+ port_name new_resource.port_name
149
+ end
150
+ end
151
+
152
+ converge_by("install driver #{new_resource.driver_name}") do
153
+ powershell_exec!("Add-PrinterDriver -Name '#{new_resource.driver_name}'")
154
+ end
155
+
156
+ converge_by("create #{@new_resource.device_id}") do
157
+ powershell_exec! <<-EOH
158
+ Set-WmiInstance -class Win32_Printer `
159
+ -EnableAllPrivileges `
160
+ -Argument @{ DeviceID = "#{new_resource.device_id}";
161
+ Comment = "#{new_resource.comment}";
162
+ Default = "$#{new_resource.default}";
163
+ DriverName = "#{new_resource.driver_name}";
164
+ Location = "#{new_resource.location}";
165
+ PortName = "#{new_resource.port_name}";
166
+ Shared = "$#{new_resource.shared}";
167
+ ShareName = "#{new_resource.share_name}";
168
+ }
169
+ EOH
100
170
  end
101
171
  end
102
172
  end
103
173
 
104
174
  action :delete, description: "Delete an existing printer. Note that this resource does not delete the associated printer port." do
105
- if printer_exists?
175
+ if current_resource
106
176
  converge_by("Delete #{new_resource.device_id}") do
107
177
  powershell_exec!("Remove-Printer -Name '#{new_resource.device_id}'")
108
178
  end
@@ -110,42 +180,6 @@ class Chef
110
180
  Chef::Log.info "#{new_resource.device_id} doesn't exist - can't delete."
111
181
  end
112
182
  end
113
-
114
- action_class do
115
- # does the printer exist
116
- #
117
- # @param [String] name the name of the printer
118
- # @return [Boolean]
119
- def printer_exists?
120
- printer_reg_key = PRINTERS_REG_KEY + new_resource.name
121
- logger.trace "Checking to see if this reg key exists: '#{printer_reg_key}'"
122
- registry_key_exists?(printer_reg_key)
123
- end
124
-
125
- # creates the printer port and then the printer
126
- def create_printer
127
- # Create the printer port first
128
- windows_printer_port new_resource.ipv4_address
129
-
130
- port_name = "IP_#{new_resource.ipv4_address}"
131
-
132
- declare_resource(:powershell_script, "Creating printer: #{new_resource.device_id}") do
133
- code <<-EOH
134
- Set-WmiInstance -class Win32_Printer `
135
- -EnableAllPrivileges `
136
- -Argument @{ DeviceID = "#{new_resource.device_id}";
137
- Comment = "#{new_resource.comment}";
138
- Default = "$#{new_resource.default}";
139
- DriverName = "#{new_resource.driver_name}";
140
- Location = "#{new_resource.location}";
141
- PortName = "#{port_name}";
142
- Shared = "$#{new_resource.shared}";
143
- ShareName = "#{new_resource.share_name}";
144
- }
145
- EOH
146
- end
147
- end
148
- end
149
183
  end
150
184
  end
151
185
  end
@@ -137,7 +137,7 @@ class Chef
137
137
 
138
138
  action :delete, description: "Delete an existing printer port." do
139
139
  if current_resource
140
- converge_by("Delete #{new_resource.port_name}") do
140
+ converge_by("delete port #{new_resource.port_name}") do
141
141
  powershell_exec!("Remove-PrinterPort -Name #{new_resource.port_name}")
142
142
  end
143
143
  else
@@ -0,0 +1,259 @@
1
+ #
2
+ # Author:: Sölvi Páll Ásgeirsson (<solvip@gmail.com>)
3
+ # Author:: Richard Lavey (richard.lavey@calastone.com)
4
+ # Author:: Tim Smith (tsmith@chef.io)
5
+ #
6
+ # Copyright:: 2014-2017, Sölvi Páll Ásgeirsson.
7
+ # Copyright:: Copyright (c) Chef Software Inc.
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ #
21
+
22
+ require_relative "../resource"
23
+ class Chef
24
+ class Resource
25
+ class WindowsUpdateSettings < Chef::Resource
26
+ unified_mode true
27
+
28
+ provides :windows_update_settings
29
+
30
+ description "Use the **windows_update_settings** resource to manage the various Windows Update patching options."
31
+ introduced "17.3"
32
+ examples <<~DOC
33
+ **Set Windows Update settings**:
34
+
35
+ ```ruby
36
+ windows_update_settings 'Settings to Configure Windows Nodes to automatically receive updates' do
37
+ disable_os_upgrades true
38
+ elevate_non_admins true
39
+ block_windows_update_website true
40
+ automatically_install_minor_updates true
41
+ scheduled_install_day 'Friday'
42
+ scheduled_install_hour 18
43
+ update_other_ms_products true
44
+ action :enable
45
+ end
46
+ ```
47
+ DOC
48
+
49
+ # required for the alias to pass validation
50
+ allowed_actions :set, :enable
51
+
52
+ DAYS = %W{Everyday Monday Tuesday Wednesday Thursday Friday Saturday Sunday}.freeze
53
+ UPDATE_OPTIONS = {
54
+ notify: 2,
55
+ download_and_notify: 3,
56
+ download_and_schedule: 4,
57
+ local_admin_decides: 5,
58
+ }.freeze
59
+
60
+ # HKLM\Software\Policies\Microsoft\Windows\WindowsUpdate
61
+
62
+ property :disable_os_upgrades, [true, false], default: false, description: "Disable OS upgrades."
63
+ # options: 0 - let windows update update the os - false
64
+ # 1 - don't let windows update update the os - true
65
+
66
+ property :elevate_non_admins, [true, false], default: true, description: "Allow normal user accounts to temporarily be elevated to install patches."
67
+ # options: 0 - do not elevate a user to force an install - false
68
+ # 1 - do elevate the logged on user to install an update - true
69
+
70
+ property :add_to_target_wsus_group, [true, false], deprecated: "As of Chef Infra Client 17.3 the `add_to_target_wsus_group` property is no longer necessary."
71
+ # we set this registry value now automatically if the group name is set
72
+
73
+ property :target_wsus_group_name, String, description: "Add the node to a WSUS Target Group."
74
+ # options: --- a string representing the name of a target group you defined on your wsus server
75
+
76
+ property :wsus_server_url, String, description: "The URL of your WSUS server if you use one."
77
+ # options: --- a url for your internal update server in the form of https://my.updateserver.tld:4545 or whatever
78
+
79
+ property :wsus_status_server_url, String, deprecated: "As of Chef Infra Client 17.3 the `wsus_status_server_url` no longer needs to be set."
80
+ # this needs to be the same as wsus_server_url so we just set that value in both places now
81
+
82
+ # HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer
83
+
84
+ property :block_windows_update_website, [true, false], default: false, description: "Block accessing the Windows Update website."
85
+ # options: 0 - allow access to the windows update website - false
86
+ # 1 - do not allow access to the windows update website - true
87
+
88
+ # HKLM\Software\Policies\Microsoft\Windows\WindowsUpdate\AU
89
+
90
+ property :automatic_update_option, [Integer, Symbol], equal_to: UPDATE_OPTIONS.keys, coerce: proc { |x| UPDATE_OPTIONS.key(x) || x },
91
+ default: :download_and_schedule,
92
+ description: "Control what to do when updates are found. This allows you to notify, automatically download and notify to install, automatically download and schedule the install, or let the local admin decide what action to take."
93
+ # options: 2 - notify before download
94
+ # 3 - auto download and notify
95
+ # 4 - auto download and schedule - must also set day and time (below)
96
+ # 5 - allow the local admin to decide
97
+
98
+ property :automatically_install_minor_updates, [true, false], default: false, description: "Automatically install minor updates."
99
+ # options: 0 - do not automatically install minor updates - false
100
+ # 1 - of course, silently install them! - true
101
+
102
+ property :enable_detection_frequency, [true, false], default: false, description: "Used to override the OS default of how often to check for updates"
103
+ # do i want my nodes checking for updates at a time interval i chose?
104
+ # options: 0 - do not enable the option for a custom interval - false
105
+ # 1 - yeah, buddy, i want to set my own interval for checking for updates - true
106
+
107
+ property :custom_detection_frequency, Integer, default: 22, description: "If you decided to override the OS default detection frequency, specify your choice here. Valid choices are 0 - 22",
108
+ callbacks: {
109
+ "should be a valid detection frequency (0-22)" => lambda { |p|
110
+ p >= 0 && p <= 22
111
+ },
112
+ }
113
+ # a time period of between 0 and 22 hours to check for new updates
114
+ # this is a hex value - convert it from dec to hex
115
+
116
+ property :no_reboot_with_users_logged_on, [true, false], default: true, description: "Prevents the OS from rebooting while someone is on the console."
117
+ # options: 0 - user is notified of pending reboot in xx minutes - false/off
118
+ # 1 - user is notified of pending reboot but can defer - true/on
119
+
120
+ property :disable_automatic_updates, [true, false], default: false, description: "Disable Windows Update."
121
+ # options: 0 - enable automatic updates to the local system - false
122
+ # 1 - disable automatic updates - true
123
+
124
+ property :scheduled_install_day, String, equal_to: DAYS, default: DAYS.first, description: "A day of the week to tell Windows when to install updates."
125
+ # options: Everyday - install every day
126
+ # Sunday - Saturday day of the week to install, 1 == sunday
127
+
128
+ property :scheduled_install_hour, Integer, description: "If you chose a scheduled day to install, then choose an hour on that day for you installation",
129
+ callbacks: {
130
+ "should be a valid hour in a 24 hour clock" => lambda { |p|
131
+ p > 0 && p < 25
132
+ },
133
+ }
134
+ # options: --- 2-digit number representing an hour of the day, uses a 24-hour clock, 12 == noon, 24 == midnight
135
+
136
+ property :update_other_ms_products, [true, false], default: true, description: "Allows for other Microsoft products to get updates too"
137
+ # options: 0 - do not allow wu to update other apps - remove key from hive - false/off
138
+ # 1 - please update all my stuff! - true/on
139
+
140
+ # \AU\AllowMUUpdateService dword: 1
141
+
142
+ property :custom_wsus_server, [true, false], deprecated: "As of Chef Infra Client 17.3 the `custom_wsus_server` no longer needs to be setup when specifying a WSUS endpoint."
143
+ # not necessary as we set this registry value automatically if a URL is set
144
+
145
+ action :set, description: "Set Windows Update settings." do
146
+ actual_day = convert_day(new_resource.scheduled_install_day)
147
+
148
+ registry_key 'HKEY_LOCAL_MACHINE\\Software\\Policies\\Microsoft\\Windows\\WindowsUpdate' do
149
+ recursive true
150
+ values [{
151
+ name: "DisableOSUpgrade",
152
+ type: :dword,
153
+ data: new_resource.disable_os_upgrades ? 1 : 0,
154
+ },
155
+ {
156
+ name: "ElevateNonAdmins",
157
+ type: :dword,
158
+ data: new_resource.elevate_non_admins ? 1 : 0,
159
+ },
160
+ {
161
+ name: "TargetGroupEnabled",
162
+ type: :dword,
163
+ data: new_resource.target_wsus_group_name ? 1 : 0,
164
+ },
165
+ {
166
+ name: "TargetGroup",
167
+ type: :string,
168
+ data: new_resource.target_wsus_group_name,
169
+ },
170
+ {
171
+ name: "WUServer",
172
+ type: :string,
173
+ data: new_resource.wsus_server_url,
174
+ },
175
+ {
176
+ name: "WUStatusServer",
177
+ type: :string,
178
+ data: new_resource.wsus_server_url, # status server and server need to be the same. Why? Ask Microsoft
179
+ }]
180
+ action :create
181
+ end
182
+
183
+ registry_key 'HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer' do
184
+ recursive true
185
+ values [{
186
+ name: "NoWindowsUpdate",
187
+ type: :dword,
188
+ data: new_resource.block_windows_update_website ? 1 : 0,
189
+ }]
190
+ action :create
191
+ end
192
+
193
+ registry_key 'HKEY_LOCAL_MACHINE\\Software\\Policies\\Microsoft\\Windows\\WindowsUpdate\\AU' do
194
+ recursive true
195
+ values [{
196
+ name: "AUOptions",
197
+ type: :dword,
198
+ data: UPDATE_OPTIONS[new_resource.automatic_update_option],
199
+ },
200
+ {
201
+ name: "AutoInstallMinorUpdates",
202
+ type: :dword,
203
+ data: new_resource.automatically_install_minor_updates ? 1 : 0,
204
+ },
205
+ {
206
+ name: "DetectionFrequencyEnabled",
207
+ type: :dword,
208
+ data: new_resource.enable_detection_frequency ? 1 : 0,
209
+ },
210
+ {
211
+ name: "DetectionFrequency",
212
+ type: :dword,
213
+ data: new_resource.custom_detection_frequency,
214
+ },
215
+ {
216
+ name: "NoAutoRebootWithLoggedOnUsers",
217
+ type: :dword,
218
+ data: new_resource.no_reboot_with_users_logged_on ? 1 : 0,
219
+ },
220
+ {
221
+ name: "NoAutoUpdate",
222
+ type: :dword,
223
+ data: new_resource.disable_automatic_updates ? 1 : 0,
224
+ },
225
+ {
226
+ name: "ScheduledInstallDay",
227
+ type: :dword,
228
+ data: actual_day,
229
+ },
230
+ {
231
+ name: "ScheduledInstallTime",
232
+ type: :dword,
233
+ data: new_resource.scheduled_install_hour,
234
+ },
235
+ {
236
+ name: "AllowMUUpdateService",
237
+ type: :dword,
238
+ data: new_resource.update_other_ms_products ? 1 : 0,
239
+ },
240
+ {
241
+ name: "UseWUServer",
242
+ type: :dword,
243
+ data: new_resource.wsus_server_url ? 1 : 0, # if we have a URL set then want to turn on WSUS functionality
244
+ }]
245
+ action :create
246
+ end
247
+ end
248
+
249
+ action_class do
250
+ def convert_day(day)
251
+ DAYS.index(day)
252
+ end
253
+
254
+ # support the old name as well
255
+ alias_method :action_enable, :action_set
256
+ end
257
+ end
258
+ end
259
+ end