diff --git a/lib/puppet/parser/functions/parse_auto_update_option.rb b/lib/puppet/parser/functions/parse_auto_update_option.rb index e8948e0..5b013ee 100644 --- a/lib/puppet/parser/functions/parse_auto_update_option.rb +++ b/lib/puppet/parser/functions/parse_auto_update_option.rb @@ -18,13 +18,14 @@ module Puppet::Parser::Functions autoupdate_hash = { 'notifyonly' => 2, 'autonotify' => 3, 'scheduled' => 4, - 'autoinstall' => 5 } + 'autoinstall' => 5, + 'notifyrestart' => 7 } option = args[0] - error_msg = "Valid options for auto_update_option are NotifyOnly|AutoNotify|Scheduled|AutoInstall|2|3|4|5, provided '#{option}'" + error_msg = "Valid options for auto_update_option are NotifyOnly|AutoNotify|Scheduled|AutoInstall|NotifyRestart|2|3|4|5|7, provided '#{option}'" if option.is_a?(Numeric) || option =~ %r{^\d$} option = Integer(option) if option.is_a?(String) - raise Puppet::ParseError, error_msg if option < 2 || option > 5 + raise Puppet::ParseError, error_msg if option < 2 || option > 7 return option end diff --git a/manifests/init.pp b/manifests/init.pp index 3d87816..1278dd8 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -140,7 +140,8 @@ Optional[Variant[Stdlib::HTTPUrl,Boolean]] $server_url = undef, Optional[Boolean] $enable_status_server = undef, Optional[Boolean] $accept_trusted_publisher_certs = undef, - Optional[Variant[Enum['NotifyOnly', 'AutoNotify', 'Scheduled', 'AutoInstall'],Integer[2,5]]] $auto_update_option = undef, + Optional[Variant[Enum['NotifyOnly', 'AutoNotify', 'Scheduled', 'AutoInstall', 'NotifyRestart'],Integer[2,5],Integer[7,7]]] + $auto_update_option = undef, Optional[Boolean] $auto_install_minor_updates = undef, Optional[Variant[Integer[1,22],Boolean]] $detection_frequency_hours = undef, Optional[Boolean] $disable_windows_update_access = undef, @@ -212,6 +213,16 @@ if $auto_update_option { $_parsed_auto_update_option = parse_auto_update_option($auto_update_option) + + # Option 7 is only supported on Windows Server 2016 and later. + if $_parsed_auto_update_option == 7 { + # Windows 2012's major version in facter is "2012 R2" which cannot be converted to integer directly. + # So, extract the leading digits from the major release string. + $_windows_version = regsubst($facts['os']['release']['major'], '^(\d+).*$', '\1') + if (Integer($_windows_version) < 2016) { + fail('auto_update_option value 7 is only supported on Windows Server 2016 and later.') + } + } if $_parsed_auto_update_option == 4 and !($scheduled_install_day and $scheduled_install_hour) { fail("scheduled_install_day and scheduled_install_hour required when specifying auto_update_option => '${auto_update_option}'") } diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 289b151..a601bbd 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -241,7 +241,7 @@ auto_update_option: au_opt } end - let(:error_message) { %r{expects a value of type Undef, Enum\['AutoInstall', 'AutoNotify', 'NotifyOnly', 'Scheduled'\], or Integer\[2, 5\]} } + let(:error_message) { %r{expects a value of type Undef, Enum\['AutoInstall', 'AutoNotify', 'NotifyOnly', 'NotifyRestart', 'Scheduled'\], Integer\[2, 5\], or Integer\[7, 7\]} } it_behaves_like 'fail validation' end diff --git a/spec/functions/parse_auto_update_option_spec.rb b/spec/functions/parse_auto_update_option_spec.rb index 2bedddb..2b561ce 100644 --- a/spec/functions/parse_auto_update_option_spec.rb +++ b/spec/functions/parse_auto_update_option_spec.rb @@ -6,7 +6,8 @@ expected_hash = { 'NotifyOnly' => 2, 'AutoNotify' => 3, 'Scheduled' => 4, - 'AutoInstall' => 5 } + 'AutoInstall' => 5, + 'NotifyRestart' => 7 } expected_hash.each_key do |auto_update_option| describe "when parsing #{auto_update_option}" do @@ -41,7 +42,7 @@ expect { scope.function_parse_auto_update_option(['Whatthe']) }.to raise_error(Puppet::Error, - "Valid options for auto_update_option are #{expected_hash.keys.join('|')}|2|3|4|5, provided 'Whatthe'") + "Valid options for auto_update_option are #{expected_hash.keys.join('|')}|2|3|4|5|7, provided 'Whatthe'") end end end