Closed alfonsrv closed 1 year ago
By specifying windows_update
the module is going to do ServerSelection = ssWindowsUpdate
which the docs indicate it's the Windows Update service. In your issue description you mentioned having a WSUS server which will be ignored if you do server_selection: windows_update
. Have you tried not specifying server_selection
or doing server_selection: managed_server
?
Also thank you for the video to describe the issue, it makes it a lot easier to try and understand what is happening here.
Initially I tried using server_selection: windows_update
, however that did not seem to work reliably on all machines. So I admitted all updates on the WSUS server and set it back to the default server_selection: managed_server
. After waiting a bit and executing the command multiple times, switching server_selection
forward and backward, some function updates could not be installed. This included Windows Malicious Software Removal Tool, Updates for Microsoft SQL Server, Updates for Exchange Servers.
For all these instances the behavior was the same as shown in the video and had to be installed via GUI. Could be that it's Windows Server 2012 R2 and Feature Updates aren't implemented properly in the API or sth.
I also ran this code I found you outlined somewhere, and it didn't list the updates in question either. Didn't cross check with other tools like this, but might next time – likely uses the same API tho https://github.com/EliaSaSe/windows-update-remote-service
$ErrorActionPreference = "Stop"
$session = New-Object -ComObject Microsoft.Update.Session
$searcher = $session.CreateUpdateSearcher()
$search_result = $searcher.Search("IsInstalled = 0")
foreach ($update in $search_result.Updates) {
$categories = @()
foreach ($category in $update.Categories) {
$categories += "$($category.Name) - $($category.CategoryID)"
}
$kbs = @()
foreach ($kb in $update.KBArticleIDs) {
$kbs += $kb
}
[PSCustomObject]@{
Categories = $categories
Description = $update.Description
Hidden = $update.IsHidden
Id = $update.Identity.UpdateID
KBs = $kbs
Mandatory = $update.IsMandatory
Present = $update.IsPresent
Title = $update.Title
}
}
Thanks for sharing the info, unfortunately I think I'm just going to have to try and set up a similar environment to yourself and test it out. I don't know why the API is not returning the info, the script you shared is pretty much what win_updates
does locally.
I noticed it behaves similarly for other "Feature Updates" such as MSSQL. Might make it easier to build an environment around that.
I spent a bit of time last week and today and unfortunately I cannot replicate this problem. I installed SQL Server Express 2016 and set up a WSUS environment. The Server 2012 R2 host was configured with the following registry policies to point to the WSUS server:
- name: configure WSUS registry settings
win_regedit:
path: HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate{{ item.path }}
name: '{{ item.name }}'
data: '{{ item.data }}'
type: '{{ item.type | default("string") }}'
state: present
loop:
- path: ''
name: WUServer
data: http://{{ wsus_server }}:8530
- path: ''
name: WUStatusServer
data: http://{{ wsus_server }}:8530
- path: ''
name: DoNotConnectToWindowsUpdateInternetLocations
data: 1
type: dword
- path: \AU
name: UseWUServer
data: 1
type: dword
SQL Server Express 2016 SP2 was updated and after running Ansible it found the following updates:
ok: [APP] => changed=false
failed_update_count: 0
filtered_updates:
9489d8c1-9a07-471f-8d76-62a841c3a22e:
categories:
- Microsoft SQL Server 2016
- Service Packs
downloaded: false
filtered_reason: category_names
filtered_reasons:
- category_names
id: 9489d8c1-9a07-471f-8d76-62a841c3a22e
installed: false
kb:
- '5003279'
title: SQL Server 2016 Service Pack 3 (KB5003279)
found_update_count: 2
installed_update_count: 0
reboot_required: false
rebooted: false
updates:
2681c9db-3adb-4069-830b-e998c31bc37b:
categories:
- Microsoft SQL Server 2016
- Security Updates
downloaded: false
id: 2681c9db-3adb-4069-830b-e998c31bc37b
installed: false
kb:
- '5014351'
title: Security Update for SQL Server 2016 Service Pack 2 CU (KB5014351)
485fee55-15be-4183-844f-67f717c2c794:
categories:
- Microsoft SQL Server 2016
- Security Updates
downloaded: false
id: 485fee55-15be-4183-844f-67f717c2c794
installed: false
kb:
- '5014365'
title: Security Update for SQL Server 2016 Service Pack 2 GDR (KB5014365)
I even cleared out the local update cache to try it again and it was always able to find the latest updates. I tried all sorts of permutations but no matter what I tried it never failed to find the SQL server updates from the WSUS server.
I can confirm that searching through the COM API (whether through Ansible or manually in PowerShell) will reset the GUI back to the default "Search for updates" screen but that just seems to be a byproduct of the API. I cannot find any documentation on that so I am just assuming that's the behaviour. It makes some sense because if another process has updated the update cache by potentially installing updates or by hiding updates; the GUI would want to check again to make sure it has the latest list available.
Unfortunately there's not much else I can do here, from what I can see the module just calls the Windows Update API and I can get it working in my test environment. If this is still a problem for you my only recommendation is to contact Microsoft support to see why their API is not getting the updates you expect with that PowerShell example you tried in https://github.com/ansible-collections/ansible.windows/issues/471#issuecomment-1401088767. That's essentially what the module is doing and if Microsoft's own API isn't returning the results expected then it's most likely some sort of misconfiguration or problem in their client.
SUMMARY
Available Windows Updates are not shown reliably, even after being allowed through e.g. WSUS. Ansible finds 0 updates; triggering searching via GUI finds new updates however. Re-running ansible afterwards causes it to disappear from the GUI again. Might be related to https://github.com/ansible-collections/ansible.windows/issues/87
Recorded the behavior for better clarity here: https://youtu.be/KMRL_xCQHek
Tried changing
state
andserver_selection
to different values.ISSUE TYPE
COMPONENT NAME
win_update
ANSIBLE VERSION
COLLECTION VERSION
CONFIGURATION
OS / ENVIRONMENT
EXPECTED RESULTS
Find all updates
ACTUAL RESULTS
Does not find available Exchange update, even though it's available when using the GUI.