Skip to content

Commit 6a1ab64

Browse files
(MODULES-11590) Add support for option 7 to parameter 'auto_update_option'
Option 7: Notify for install and notify for restart. (Windows Server 2016 and later only) For more details see: https://learn.microsoft.com/en-us/windows/deployment/update/waas-wu-settings
1 parent b879748 commit 6a1ab64

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

lib/puppet/parser/functions/parse_auto_update_option.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ module Puppet::Parser::Functions
1818
autoupdate_hash = { 'notifyonly' => 2,
1919
'autonotify' => 3,
2020
'scheduled' => 4,
21-
'autoinstall' => 5 }
21+
'autoinstall' => 5,
22+
'notifyrestart' => 7 }
2223

2324
option = args[0]
24-
error_msg = "Valid options for auto_update_option are NotifyOnly|AutoNotify|Scheduled|AutoInstall|2|3|4|5, provided '#{option}'"
25+
error_msg = "Valid options for auto_update_option are NotifyOnly|AutoNotify|Scheduled|AutoInstall|NotifyRestart|2|3|4|5|7, provided '#{option}'"
2526
if option.is_a?(Numeric) || option =~ %r{^\d$}
2627
option = Integer(option) if option.is_a?(String)
27-
raise Puppet::ParseError, error_msg if option < 2 || option > 5
28+
raise Puppet::ParseError, error_msg if option < 2 || option > 7
2829

2930
return option
3031
end

manifests/init.pp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@
140140
Optional[Variant[Stdlib::HTTPUrl,Boolean]] $server_url = undef,
141141
Optional[Boolean] $enable_status_server = undef,
142142
Optional[Boolean] $accept_trusted_publisher_certs = undef,
143-
Optional[Variant[Enum['NotifyOnly', 'AutoNotify', 'Scheduled', 'AutoInstall'],Integer[2,5]]] $auto_update_option = undef,
143+
Optional[Variant[Enum['NotifyOnly', 'AutoNotify', 'Scheduled', 'AutoInstall', 'NotifyRestart'],Integer[2,5],Integer[7,7]]]
144+
$auto_update_option = undef,
144145
Optional[Boolean] $auto_install_minor_updates = undef,
145146
Optional[Variant[Integer[1,22],Boolean]] $detection_frequency_hours = undef,
146147
Optional[Boolean] $disable_windows_update_access = undef,
@@ -212,6 +213,16 @@
212213

213214
if $auto_update_option {
214215
$_parsed_auto_update_option = parse_auto_update_option($auto_update_option)
216+
217+
# Option 7 is only supported on Windows Server 2016 and later.
218+
if $_parsed_auto_update_option == 7 {
219+
# Windows 2012's major version in facter is "2012 R2" which cannot be converted to integer directly.
220+
# So, extract the leading digits from the major release string.
221+
$_windows_version = regsubst($facts['os']['release']['major'], '^(\d+).*$', '\1')
222+
if (Integer($_windows_version) < 2016) {
223+
fail('auto_update_option value 7 is only supported on Windows Server 2016 and later.')
224+
}
225+
}
215226
if $_parsed_auto_update_option == 4 and !($scheduled_install_day and $scheduled_install_hour) {
216227
fail("scheduled_install_day and scheduled_install_hour required when specifying auto_update_option => '${auto_update_option}'")
217228
}

spec/classes/init_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@
241241
auto_update_option: au_opt
242242
}
243243
end
244-
let(:error_message) { %r{expects a value of type Undef, Enum\['AutoInstall', 'AutoNotify', 'NotifyOnly', 'Scheduled'\], or Integer\[2, 5\]} }
244+
let(:error_message) { %r{expects a value of type Undef, Enum\['AutoInstall', 'AutoNotify', 'NotifyOnly', 'NotifyRestart', 'Scheduled'\], Integer\[2, 5\], or Integer\[7, 7\]} }
245245

246246
it_behaves_like 'fail validation'
247247
end

0 commit comments

Comments
 (0)