diff --git a/plugins/modules/win_updates.ps1 b/plugins/modules/win_updates.ps1 index d638dc3a..d98a2e0a 100644 --- a/plugins/modules/win_updates.ps1 +++ b/plugins/modules/win_updates.ps1 @@ -17,6 +17,11 @@ $spec = @{ elements = 'str' default = 'CriticalUpdates', 'SecurityUpdates', 'UpdateRollups' } + reject_category_names = @{ + type = 'list' + elements = 'str' + default = [] + } log_path = @{ type = 'path' } reject_list = @{ type = 'list'; elements = 'str' } server_selection = @{ type = 'str'; choices = 'default', 'managed_server', 'windows_update'; default = 'default' } @@ -1054,6 +1059,10 @@ Function Install-WindowsUpdate { [String[]] $Category, + [Parameter(Mandatory)] + [String[]] + $RejectCategory, + [Parameter(Mandatory)] [String] $ServerSelection, @@ -1823,6 +1832,14 @@ namespace Ansible.Windows.WinUpdates break } } + + $categoryReject = $false + foreach ($matchCat in $Category) { + if ($matchCat -eq '*' -or $updateInfo.categories -ieq $matchCat) { + $categoryReject = $true + break + } + } $matchList = ($updateInfo.title + $updateInfo.kb) $filteredReasons = [System.Collections.Generic.List[String]]@() @@ -1838,6 +1855,9 @@ namespace Ansible.Windows.WinUpdates if (-not $categoryMatch) { $filteredReasons.Add('category_names') } + if ($categoryReject) { + $filteredReasons.Add('reject_category_names') + } if ($SkipOptional) { If ($updateInfo.browse_only) { @@ -2067,6 +2087,19 @@ $categoryNames = $module.Params.category_names | ForEach-Object -Process { } } +$rejectCategoryNames = $module.Params.reject_category_names | ForEach-Object -Process { + switch -exact ($_) { + CriticalUpdates { 'Critical Updates' } + DefinitionUpdates { 'Definition Updates' } + DeveloperKits { 'Developer Kits' } + FeaturePacks { 'Feature Packs' } + SecurityUpdates { 'Security Updates' } + ServicePacks { 'Service Packs' } + UpdateRollups { 'Update Rollups' } + default { $_ } + } +} + <# Most of the Windows Update Agent API will not run under a remote token which is typically what a WinRM process is. We can use a scheduled task to change the logon to a batch/service logon allowing us to bypass that restriction if @@ -2176,6 +2209,7 @@ else { $updateParameters = @{ Category = $categoryNames + RejectCategory = $rejectCategoryNames Accept = @(if ($module.Params.accept_list) { $module.Params.accept_list }) Reject = @(if ($module.Params.reject_list) { $module.Params.reject_list }) ServerSelection = $module.Params.server_selection diff --git a/plugins/modules/win_updates.py b/plugins/modules/win_updates.py index 941a9e3c..aff109ae 100644 --- a/plugins/modules/win_updates.py +++ b/plugins/modules/win_updates.py @@ -37,6 +37,17 @@ type: list elements: str default: [ CriticalUpdates, SecurityUpdates, UpdateRollups ] + reject_category_names: + description: + - A scalar or list of categories to reject updates from. To get the list + of categories, run the module with C(state=searched). The category must + be the full category string, but is case insensitive. + - Some possible categories are Application, Connectors, Critical Updates, + Definition Updates, Developer Kits, Feature Packs, Guidance, Security + Updates, Service Packs, Tools, Update Rollups, Updates, and Upgrades. + type: list + elements: str + default: [] skip_optional: description: - Skip optional updates where the update has BrowseOnly set by Microsoft. @@ -172,6 +183,18 @@ # connection. ansible_ssh_args: -o ControlMaster=no -o ServerAliveInterval=30 +- name: Install all security, critical, and rollup updates except Office 2016 updates without a scheduled task + ansible.windows.win_updates: + category_names: + - SecurityUpdates + - CriticalUpdates + - UpdateRollups + reject_category_names: + - Office 2016 + become: true + become_method: runas + become_user: SYSTEM + - name: Install all security, critical, and rollup updates without a scheduled task ansible.windows.win_updates: category_names: @@ -293,7 +316,7 @@ filtered_updates: description: Updates that were found but were filtered based on - I(blacklist), I(whitelist) or I(category_names). The return value is in + I(blacklist), I(whitelist), I(category_names) or I(reject_category_names). The return value is in the same form as I(updates). returned: success type: dict @@ -302,7 +325,7 @@ filtered_reasons: description: - A list of reasons why the update has been filtered. - - Can be C(accept_list), C(reject_list), C(hidden), C(category_names), or C(skip_optional). + - Can be C(accept_list), C(reject_list), C(hidden), C(category_names), C(reject_category_names) or C(skip_optional). type: list elements: str sample: