Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions plugins/modules/win_updates.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand Down Expand Up @@ -1054,6 +1059,10 @@ Function Install-WindowsUpdate {
[String[]]
$Category,

[Parameter(Mandatory)]
[String[]]
$RejectCategory,

[Parameter(Mandatory)]
[String]
$ServerSelection,
Expand Down Expand Up @@ -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]]@()
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
27 changes: 25 additions & 2 deletions plugins/modules/win_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
Loading