ansible-collections / ansible.windows

Windows core collection for Ansible
https://galaxy.ansible.com/ansible/windows
GNU General Public License v3.0
245 stars 167 forks source link

win_updates: can't update reboot_required status on WinServer 2019 #25

Closed jborean93 closed 3 years ago

jborean93 commented 4 years ago

From @pawellrus on Jul 13, 2019 14:12

SUMMARY

I faced with a strange issue when I was trying to install updates for Windows Server 2019. Playbook stuck in rebooting loop.

ISSUE TYPE
COMPONENT NAME
win_updates
ANSIBLE VERSION
ansible 2.8.1
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/polushin/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Jun 20 2019, 20:27:34) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)
STEPS TO REPRODUCE
- name: Check for Updates
    win_updates:
      state: searched
      category_names: ['Application','CriticalUpdates','DefinitionUpdates','FeaturePacks','SecurityUpdates','ServicePacks','Tools','UpdateRollups','Updates']
      log_path: 'c:/ansible_wu.txt'
    register: searched

  - name: Return update list
    debug:
      msg: '{{ item }}'
    loop: "{{ searched.updates|json_query('*.title[]') }}"

  - name: Install updates
    win_updates:
      category_names: ['Application','CriticalUpdates','DefinitionUpdates','FeaturePacks','SecurityUpdates','ServicePacks','Tools','UpdateRollups','Updates']
      log_path: 'c:/ansible_wu.txt'
      reboot: yes
    when: searched.found_update_count>0
EXPECTED RESULTS

Windows Server gets updated.

ACTUAL RESULTS

reboot_required status isn't get lifted after ansible initiated reboot. Playbook stuck in reboot loop. User needs to log on to server and reboot server from Windows Update GUI.


2019-07-13 08:18:03Z WUA is available in current logon process, running natively
2019-07-13 08:18:03Z Creating Windows Update session...
2019-07-13 08:18:03Z Create Windows Update searcher...
2019-07-13 08:18:03Z Setting the Windows Update Agent source catalog...
2019-07-13 08:18:03Z Requested search source is 'default'
2019-07-13 08:18:03Z Search source set to 'default' (ServerSelection = 0)
2019-07-13 08:18:03Z Searching for updates to install
2019-07-13 08:18:10Z Found 1 updates
2019-07-13 08:18:10Z Creating update collection...
2019-07-13 08:18:10Z Adding update 299b218e-aa1b-400f-8364-7088a4061dbf - 2019-07 Cumulative Update for Windows Server 2019 (1809) for x64-based Systems (KB4507469)
2019-07-13 08:18:10Z Calculating pre-install reboot requirement...
2019-07-13 08:18:10Z No reboot is pending...
2019-07-13 08:18:10Z Downloading updates...
2019-07-13 08:18:10Z Update (1 of 1) 299b218e-aa1b-400f-8364-7088a4061dbf already downloaded, skipping...
2019-07-13 08:18:10Z Installing updates...
2019-07-13 08:18:10Z Creating installer object...
2019-07-13 08:18:10Z Creating install collection...
2019-07-13 08:18:10Z Adding update 299b218e-aa1b-400f-8364-7088a4061dbf
2019-07-13 08:18:12Z Update (1 of 1) 299b218e-aa1b-400f-8364-7088a4061dbf succeeded
2019-07-13 08:18:12Z Performing post-install reboot requirement check...
2019-07-13 08:18:12Z Return value:
{
    "updates":  {
                    "299b218e-aa1b-400f-8364-7088a4061dbf":  {
                                                                 "id":  "299b218e-aa1b-400f-8364-7088a4061dbf",
                                                                 "title":  "2019-07 Cumulative Update for Windows Server 2019 (1809) for x64-based Systems (KB4507469)",
                                                                 "categories":  [
                                                                                    "Security Updates"
                                                                                ],
                                                                 "kb":  [
                                                                            "4507469"
                                                                        ],
                                                                 "installed":  true
                                                             }
                },
    "failed_update_count":  0,
    "found_update_count":  1,
    "changed":  false,
    "reboot_required":  true,
    "installed_update_count":  1,
    "filtered_updates":  {

                         }
}
2019-07-13 08:18:12Z Native job completed with output: 
Name                           Value                                                                                                                                                                                                                                                                        
----                           -----                                                                                                                                                                                                                                                                        
updates                        {299b218e-aa1b-400f-8364-7088a4061dbf}                                                                                                                                                                                                                                       
failed_update_count            0                                                                                                                                                                                                                                                                            
found_update_count             1                                                                                                                                                                                                                                                                            
changed                        False                                                                                                                                                                                                                                                                        
reboot_required                True                                                                                                                                                                                                                                                                         
installed_update_count         1                                                                                                                                                                                                                                                                            
filtered_updates               {}                                                                                                                                                                                                                                                                           

2019-07-13 08:18:34Z WUA is available in current logon process, running natively
2019-07-13 08:18:34Z Creating Windows Update session...
2019-07-13 08:18:34Z Create Windows Update searcher...
2019-07-13 08:18:34Z Setting the Windows Update Agent source catalog...
2019-07-13 08:18:34Z Requested search source is 'default'
2019-07-13 08:18:34Z Search source set to 'default' (ServerSelection = 0)
2019-07-13 08:18:35Z Searching for updates to install
2019-07-13 08:18:41Z Found 1 updates
2019-07-13 08:18:41Z Creating update collection...
2019-07-13 08:18:41Z Adding update 299b218e-aa1b-400f-8364-7088a4061dbf - 2019-07 Cumulative Update for Windows Server 2019 (1809) for x64-based Systems (KB4507469)
2019-07-13 08:18:41Z Calculating pre-install reboot requirement...
2019-07-13 08:18:41Z No reboot is pending...
2019-07-13 08:18:41Z Downloading updates...
2019-07-13 08:18:41Z Update (1 of 1) 299b218e-aa1b-400f-8364-7088a4061dbf already downloaded, skipping...
2019-07-13 08:18:41Z Installing updates...
2019-07-13 08:18:41Z Creating installer object...
2019-07-13 08:18:41Z Creating install collection...
2019-07-13 08:18:41Z Adding update 299b218e-aa1b-400f-8364-7088a4061dbf
2019-07-13 08:18:43Z Update (1 of 1) 299b218e-aa1b-400f-8364-7088a4061dbf succeeded
2019-07-13 08:18:43Z Performing post-install reboot requirement check...
2019-07-13 08:18:43Z Return value:
{
    "updates":  {
                    "299b218e-aa1b-400f-8364-7088a4061dbf":  {
                                                                 "id":  "299b218e-aa1b-400f-8364-7088a4061dbf",
                                                                 "title":  "2019-07 Cumulative Update for Windows Server 2019 (1809) for x64-based Systems (KB4507469)",
                                                                 "categories":  [
                                                                                    "Security Updates"
                                                                                ],
                                                                 "kb":  [
                                                                            "4507469"
                                                                        ],
                                                                 "installed":  true
                                                             }
                },
    "failed_update_count":  0,
    "found_update_count":  1,
    "changed":  false,
    "reboot_required":  true,
    "installed_update_count":  1,
    "filtered_updates":  {

                         }
}
2019-07-13 08:18:43Z Native job completed with output: 
Name                           Value                                                                                                                                                                                                                                                                        
----                           -----                                                                                                                                                                                                                                                                        
updates                        {299b218e-aa1b-400f-8364-7088a4061dbf}                                                                                                                                                                                                                                       
failed_update_count            0                                                                                                                                                                                                                                                                            
found_update_count             1                                                                                                                                                                                                                                                                            
changed                        False                                                                                                                                                                                                                                                                        
reboot_required                True                                                                                                                                                                                                                                                                         
installed_update_count         1                                                                                                                                                                                                                                                                            
filtered_updates               {}  

_Copied from original issue: ansible/ansible#59056_
jborean93 commented 4 years ago

From @ShachafGoldstein on Jul 13, 2019 21:40

This could be a problem with the specific update - it has a lot of ui components, it might require an interactive logon to complete correctly I'll try to test it but updates are a tricky one

jborean93 commented 4 years ago

From @ShachafGoldstein on Aug 10, 2019 13:27

@pawellrus - has this happened with any other update since?

jborean93 commented 4 years ago

From @pawellrus on Aug 10, 2019 13:32

@ShachafGoldstein, i will check it soon. May be on next week.

jborean93 commented 4 years ago

From @swickera on Sep 13, 2019 19:31

I've seen this too, and most recently today trying to install the round of September 2019 updates. It seems related to the 2019-09 cumulative rollup.. this keeps repeating over and over:

'WINRM STDOUT {"updates":{"644bb2c6-0f42-4216-8c9a-96541b6fbaa3":{"id":"644bb2c6-0f42-4216-8c9a-96541b6fbaa3","title":"2019-09 Cumulative Update for Windows Server 2019 (1809) for x64-based Systems (KB4512578)","categories":["Security Updates"],"kb":["4512578"],"installed":true}},"failed_update_count":0,"found_update_count":1,"changed":false,"reboot_required":true,"installed_update_count":1,"filtered_updates":{}}^[[0m'

jborean93 commented 4 years ago

From @pawellrus on Sep 17, 2019 13:42

Hello again. September updates was installed without this issue in my environment.

jborean93 commented 4 years ago

From @swickera on Sep 17, 2019 14:38

update: I seem to be able to work around the issue by forcing a reboot before calling the win_updates module...

jborean93 commented 4 years ago

From @pawellrus on Oct 31, 2019 12:47

Got the same infinite reboot cycle today again. Servers were clean-deployed before. I had to log on manually to each server and reload update process from gui. All servers had 0x80240007 update error in gui.

jborean93 commented 4 years ago

From @ShachafGoldstein on Nov 17, 2019 06:43

Can you say which updates were installed? since that error is a very generic error of WU it has hard to pinpoint the issue.

jborean93 commented 4 years ago

From @pawellrus on Nov 18, 2019 07:25

That was October cumulative update KB4519338.

I has another issue recently with searching of new updates. New updates weren't been found when running process from ansible. But starting update process from GUI gave a couple of new updates. But that issue gone after some time.

I didn't experienced such problems at older versions of WinServer. There is definetely some issue in server 2019 that makes win_update module unreliable.

jborean93 commented 4 years ago

From @ShachafGoldstein on Nov 18, 2019 13:38

I Don't we have any way to resolve this. it seems like changes in how MS deploys updates to these versions. they require human intervention.

On Mon, 18 Nov 2019 at 09:27, pawellrus notifications@github.com wrote:

That was October cumulative update KB4519338.

I has another issue recently with searching of new updates. New updates weren't been found when running process from ansible. But starting update process from GUI gave a couple of new updates. But that issue gone after some time.

I didn't experienced such problems at older versions of WinServer. There is definetely some issue in server 2019 that makes win_update module unreliable.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ansible/ansible/issues/59056?email_source=notifications&email_token=ACV27RV6OVKBI2LVQ5IX6JTQUI7VBA5CNFSM4IC5CDX2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEEJOM4Y#issuecomment-554886771, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACV27RXW2RD3JPQYOVS2NLLQUI7VBANCNFSM4IC5CDXQ .

jborean93 commented 4 years ago

From @jpgrall on Nov 25, 2019 21:23

Same issue is happening for the November cumulative update (KB4523205).

jborean93 commented 4 years ago

From @jpgrall on Nov 26, 2019 13:09

Adding a win_reboot just before the start of win_update seems to have provided a valid work around. BTW, In my scenario this playbook is being ran on a new system build.

jborean93 commented 4 years ago

From @ShachafGoldstein on Nov 26, 2019 19:49

Do you see the server rebooting in your scenarios?, could the issue be around not actually rebooting the server?

jborean93 commented 4 years ago

From @jpgrall on Nov 26, 2019 22:04

Yes, it's kicking off a reboot shortly after the attempted install. It's as if it gets a completed return call rather than a wait. Adding the manual reboot before the win_update process is working on multiple runs now.

jborean93 commented 4 years ago

From @ShachafGoldstein on Nov 26, 2019 22:10

So if you simply reboot and then install updates everything works? Or you reboot between updates?

Can you post a verbose output of a failed one and a working one?

jborean93 commented 4 years ago

From @mhazri on Feb 13, 2020 04:31

Hi I have similar issue, windows update successfully and along the process the window is rebooted few time successfully. But on the ansible result, "reboot_required=false". reboot_required_false_issue

jborean93 commented 4 years ago

From @ShachafGoldstein on Mar 02, 2020 17:09

@mhazri Seems you are talking about something else, this issue is about reboot loop caused by Ansible. Maybe open a different issue on your problem?

jpgrall commented 4 years ago

From @ShachafGoldstein on Nov 26, 2019 22:10

So if you simply reboot and then install updates everything works? Or you reboot between updates?

Can you post a verbose output of a failed one and a working one?

@ShachafGoldstein - Sorry for the late reply. I'm using @jborean93 update task in his packer-windoze repo. The only thing I changed was adding the win_reboot before the first run of update.yml.

Don't have any logs from when it was failing. Here's the entry of the log where the reboot starts. https://gist.github.com/jpgrall/72e745efcd048eb05e81ea77b154c316#file-win_updates-reboot-before-log-L81

japicken commented 4 years ago

Same issue seen on Windows Server Core 2019 LTSC with April 2020 update (KB4549949) and Ansible 2.9

- name: Update Windows
  win_updates:
    server_selection: windows_update
    category_names:
      - CriticalUpdates
      - SecurityUpdates
      - UpdateRollups
      - DefinitionUpdates
      - Updates
    reboot: yes

The following log is stuck in a loop. Did not have this problem with previous updates run on this base image (starting point is Windows Server Core LTSC with Feb 2020 updates). Apologies for the color codes and packer output. We are running nested Jenkins -> packer -> ansible.

It feels like ansible is not blocking when running the Windows update. In other words it reboots way quicker than it actually takes to install this update. Update takes about 3-5 minutes when run manually, win_updates reboots us immediately so the update was either never run due to a pending reboot, or win_updates thinks the update has completed before it really has.

ansible log snippet.txt

johnbui423 commented 3 years ago

I have a very similar issue on Windows 10 - when trying to do a feature upgrade from 1809 to 1909 using ansible. (Let me know if you prefer me to open a separate issue on this instead.)

Test playbook

---

- hosts: windows
  gather_facts: yes

  tasks:
  - name: Check for upgrade
    win_updates:
      state: searched
      # Force use of WSUS
      server_selection: managed_server
      category_names:
      - Upgrades
      reboot: yes
      log_path: "c:/ansible_wu_search.txt"
    register: searched

  - name: Return update list
    debug:
      msg: '{{ item }}'
    loop: "{{ searched.updates|json_query('*.title[]') }}"

  - name: Upgrade
    win_updates:
      # Force use of WSUS
      server_selection: managed_server
      category_names:
      - Upgrades
      reboot: yes
      log_path: "c:/ansible_wu.txt"
    when: searched.found_update_count>0

Output

ansible-playbook 2.9.9
  config file = /home/test/ansible.cfg
  configured module search path = ['/home/test/library']
  ansible python module location = /usr/local/lib64/python3.6/site-packages/ansible
  executable location = /usr/local/bin/ansible-playbook
  python version = 3.6.8 (default, Apr  2 2020, 13:34:55) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]

[...]

PLAYBOOK: test_upgrade.yml ***********************************************************************************
1 plays in test_upgrade.yml

PLAY [windows] ***********************************************************************************************

TASK [Gathering Facts] ***************************************************************************************
task path: /home/test/test_upgrade.yml:3
Using module file /usr/local/lib64/python3.6/site-packages/ansible/modules/windows/setup.ps1
Pipelining is enabled.
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
EXEC (via pipeline wrapper)
ok: [TESTIP]
META: ran handlers

TASK [Check for upgrade] *************************************************************************************
task path: /home/test/test_upgrade.yml:7
win_updates: running win_updates module
Using module file /usr/local/lib64/python3.6/site-packages/ansible/modules/windows/win_updates.ps1
Pipelining is enabled.
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
EXEC (via pipeline wrapper)
ok: [TESTIP] => {
    "changed": false,
    "filtered_updates": {},
    "found_update_count": 1,
    "installed_update_count": 0,
    "reboot_required": false,
    "updates": {
        "0d500afc-802b-4b0e-b4cc-4087f87602ff": {
            "categories": [
                "Upgrades",
                "Windows 10, version 1903 and later"
            ],
            "id": "0d500afc-802b-4b0e-b4cc-4087f87602ff",
            "installed": false,
            "kb": [
                "3012973"
            ],
            "title": "Feature update to Windows 10 (business editions), version 1909, en-gb x64"
        }
    }
}

TASK [Return update list] ************************************************************************************
task path: /home/test/test_upgrade.yml:18
ok: [TESTIP] => (item=Feature update to Windows 10 (business editions), version 1909, en-gb x64) => {
    "msg": "Feature update to Windows 10 (business editions), version 1909, en-gb x64"
}

TASK [Upgrade] ***********************************************************************************************
task path: /home/test/test_upgrade.yml:23
win_updates: running win_updates module
Using module file /usr/local/lib64/python3.6/site-packages/ansible/modules/windows/win_updates.ps1
Pipelining is enabled.
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
EXEC (via pipeline wrapper)
win_updates: check win_updates results for automatic reboot: {"updates": {"0d500afc-802b-4b0e-b4cc-4087f87602ff": {"id": "0d500afc-802b-4b0e-b4cc-4087f87602ff", "title": "Feature update to Windows 10 (business editions), version 1909, en-gb x64", "categories": ["Upgrades", "Windows 10, version 1903 and later"], "kb": ["3012973"], "installed": true}}, "failed_update_count": 0, "found_update_count": 1, "changed": false, "reboot_required": true, "installed_update_count": 1, "filtered_updates": {}, "_ansible_parsed": true}
win_updates: rebooting remote host after update install
EXEC (via pipeline wrapper)
win_updates: rebooting server...
EXEC (via pipeline wrapper)
win_updates: validating reboot
win_updates: attempting to get system boot time
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
EXEC (via pipeline wrapper)
win_updates: attempting to get system boot time
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
EXEC (via pipeline wrapper)
win_updates: attempting to get system boot time
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
EXEC (via pipeline wrapper)
win_updates: attempting to get system boot time
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
win_updates: attempting to get system boot time
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
win_updates: attempting to get system boot time
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
win_updates: attempting to get system boot time
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
win_updates: attempting to get system boot time
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
win_updates: attempting to get system boot time
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
win_updates: attempting to get system boot time
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
win_updates: attempting to get system boot time
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
win_updates: attempting to get system boot time
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
win_updates: attempting to get system boot time
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
win_updates: attempting to get system boot time
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
EXEC (via pipeline wrapper)
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
win_updates: attempting post-reboot test command
EXEC (via pipeline wrapper)
win_updates: system successfully rebooted
win_updates: checking WUA is not busy with win_shell command
Using module file /usr/local/lib64/python3.6/site-packages/ansible/modules/windows/win_shell.ps1
Pipelining is enabled.
EXEC (via pipeline wrapper)
win_updates: shell wait results: {"start": "2020-11-17 01:22:37.135020", "stdout": "False\r\n", "cmd": "(New-Object -ComObject Microsoft.Update.Session).CreateUpdateInstaller().IsBusy", "stderr": "", "changed": true, "rc": 0, "delta": "0:00:00.421879", "end": "2020-11-17 01:22:37.556900", "_ansible_parsed": true, "stdout_lines": ["False"], "stderr_lines": []}
win_updates: ensure the connection is up and running
wait_for_connection: attempting ping module test
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
Using module file /usr/local/lib64/python3.6/site-packages/ansible/modules/windows/win_ping.ps1
Pipelining is enabled.
EXEC (via pipeline wrapper)
win_updates: running win_updates module
Using module file /usr/local/lib64/python3.6/site-packages/ansible/modules/windows/win_updates.ps1
Pipelining is enabled.
EXEC (via pipeline wrapper)
win_updates: check win_updates results for automatic reboot: {"updates": {"0d500afc-802b-4b0e-b4cc-4087f87602ff": {"id": "0d500afc-802b-4b0e-b4cc-4087f87602ff", "title": "Feature update to Windows 10 (business editions), version 1909, en-gb x64", "categories": ["Upgrades", "Windows 10, version 1903 and later"], "kb": ["3012973"], "installed": true}}, "failed_update_count": 0, "found_update_count": 1, "changed": false, "reboot_required": true, "installed_update_count": 1, "filtered_updates": {}, "_ansible_parsed": true}
win_updates: rebooting remote host after update install
EXEC (via pipeline wrapper)
win_updates: rebooting server...
EXEC (via pipeline wrapper)
win_updates: validating reboot
win_updates: attempting to get system boot time
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
EXEC (via pipeline wrapper)
win_updates: attempting to get system boot time
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
EXEC (via pipeline wrapper)
win_updates: attempting to get system boot time
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
EXEC (via pipeline wrapper)
win_updates: attempting to get system boot time
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
EXEC (via pipeline wrapper)
win_updates: attempting to get system boot time
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
win_updates: attempting to get system boot time
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
win_updates: attempting to get system boot time
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
win_updates: attempting to get system boot time
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP
<TESTIP> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5986 TO TESTIP

[The last task (TASK [Upgrade]) and the waiting for reboot endlessly repeats...]

Log file output

2020-11-17 14:14:01Z WUA is available in current logon process, running natively
2020-11-17 14:14:01Z Creating Windows Update session...
2020-11-17 14:14:01Z Create Windows Update searcher...
2020-11-17 14:14:01Z Setting the Windows Update Agent source catalog...
2020-11-17 14:14:01Z Requested search source is 'managed_server'
2020-11-17 14:14:01Z Search source set to 'managed_server' (ServerSelection = 1)
2020-11-17 14:14:01Z Searching for updates to install
2020-11-17 14:14:03Z Found 1 updates
2020-11-17 14:14:03Z Creating update collection...
2020-11-17 14:14:03Z Adding update 0d500afc-802b-4b0e-b4cc-4087f87602ff - Feature update to Windows 10 (business editions), version 1909, en-gb x64
2020-11-17 14:14:03Z Calculating pre-install reboot requirement...
2020-11-17 14:14:03Z No reboot is pending...
2020-11-17 14:14:03Z Downloading updates...
2020-11-17 14:14:03Z Update (1 of 1) 0d500afc-802b-4b0e-b4cc-4087f87602ff already downloaded, skipping...
2020-11-17 14:14:03Z Installing updates...
2020-11-17 14:14:03Z Creating installer object...
2020-11-17 14:14:03Z Creating install collection...
2020-11-17 14:14:03Z Adding update 0d500afc-802b-4b0e-b4cc-4087f87602ff
2020-11-17 14:14:03Z Update (1 of 1) 0d500afc-802b-4b0e-b4cc-4087f87602ff succeeded
2020-11-17 14:14:03Z Performing post-install reboot requirement check...
2020-11-17 14:14:03Z Return value:
{
    "updates":  {
                    "0d500afc-802b-4b0e-b4cc-4087f87602ff":  {
                                                                 "id":  "0d500afc-802b-4b0e-b4cc-4087f87602ff",
                                                                 "title":  "Feature update to Windows 10 (business editions), version 1909, en-gb x64",
                                                                 "categories":  [
                                                                                    "Upgrades",
                                                                                    "Windows 10, version 1903 and later"
                                                                                ],
                                                                 "kb":  [
                                                                            "3012973"
                                                                        ],
                                                                 "installed":  true
                                                             }
                },
    "failed_update_count":  0,
    "found_update_count":  1,
    "changed":  false,
    "reboot_required":  true,
    "installed_update_count":  1,
    "filtered_updates":  {

                         }
}
2020-11-17 14:14:03Z Native job completed with output: 
Name                           Value                                                                                                                                                                                                                                                                        
----                           -----                                                                                                                                                                                                                                                                        
updates                        {0d500afc-802b-4b0e-b4cc-4087f87602ff}                                                                                                                                                                                                                                       
failed_update_count            0                                                                                                                                                                                                                                                                            
found_update_count             1                                                                                                                                                                                                                                                                            
changed                        False                                                                                                                                                                                                                                                                        
reboot_required                True                                                                                                                                                                                                                                                                         
installed_update_count         1                                                                                                                                                                                                                                                                            
filtered_updates               {}                                                                                                                                                                                                                                                                           

2020-11-17 14:19:31Z WUA is available in current logon process, running natively
2020-11-17 14:19:31Z Creating Windows Update session...
2020-11-17 14:19:31Z Create Windows Update searcher...
2020-11-17 14:19:31Z Setting the Windows Update Agent source catalog...
2020-11-17 14:19:31Z Requested search source is 'managed_server'
2020-11-17 14:19:31Z Search source set to 'managed_server' (ServerSelection = 1)
2020-11-17 14:19:31Z Searching for updates to install
2020-11-17 14:19:33Z Found 1 updates
2020-11-17 14:19:33Z Creating update collection...
2020-11-17 14:19:33Z Adding update 0d500afc-802b-4b0e-b4cc-4087f87602ff - Feature update to Windows 10 (business editions), version 1909, en-gb x64
2020-11-17 14:19:33Z Calculating pre-install reboot requirement...
2020-11-17 14:19:33Z No reboot is pending...
2020-11-17 14:19:33Z Downloading updates...
2020-11-17 14:19:33Z Update (1 of 1) 0d500afc-802b-4b0e-b4cc-4087f87602ff already downloaded, skipping...
2020-11-17 14:19:33Z Installing updates...
2020-11-17 14:19:33Z Creating installer object...
2020-11-17 14:19:33Z Creating install collection...
2020-11-17 14:19:33Z Adding update 0d500afc-802b-4b0e-b4cc-4087f87602ff
2020-11-17 14:19:33Z Update (1 of 1) 0d500afc-802b-4b0e-b4cc-4087f87602ff succeeded
2020-11-17 14:19:33Z Performing post-install reboot requirement check...
2020-11-17 14:19:33Z Return value:
{
    "updates":  {
                    "0d500afc-802b-4b0e-b4cc-4087f87602ff":  {
                                                                 "id":  "0d500afc-802b-4b0e-b4cc-4087f87602ff",
                                                                 "title":  "Feature update to Windows 10 (business editions), version 1909, en-gb x64",
                                                                 "categories":  [
                                                                                    "Upgrades",
                                                                                    "Windows 10, version 1903 and later"
                                                                                ],
                                                                 "kb":  [
                                                                            "3012973"
                                                                        ],
                                                                 "installed":  true
                                                             }
                },
    "failed_update_count":  0,
    "found_update_count":  1,
    "changed":  false,
    "reboot_required":  true,
    "installed_update_count":  1,
    "filtered_updates":  {

                         }
}
2020-11-17 14:19:33Z Native job completed with output: 
Name                           Value                                                                                                                                                                                                                                                                        
----                           -----                                                                                                                                                                                                                                                                        
updates                        {0d500afc-802b-4b0e-b4cc-4087f87602ff}                                                                                                                                                                                                                                       
failed_update_count            0                                                                                                                                                                                                                                                                            
found_update_count             1                                                                                                                                                                                                                                                                            
changed                        False                                                                                                                                                                                                                                                                        
reboot_required                True                                                                                                                                                                                                                                                                         
installed_update_count         1                                                                                                                                                                                                                                                                            
filtered_updates               {}                                                                                                                                                                                                                                                                           

2020-11-17 14:22:41Z WUA is available in current logon process, running natively
2020-11-17 14:22:41Z Creating Windows Update session...
2020-11-17 14:22:41Z Create Windows Update searcher...
2020-11-17 14:22:41Z Setting the Windows Update Agent source catalog...
2020-11-17 14:22:41Z Requested search source is 'managed_server'
2020-11-17 14:22:41Z Search source set to 'managed_server' (ServerSelection = 1)
2020-11-17 14:22:41Z Searching for updates to install
2020-11-17 14:22:43Z Found 1 updates
2020-11-17 14:22:44Z Creating update collection...
2020-11-17 14:22:44Z Adding update 0d500afc-802b-4b0e-b4cc-4087f87602ff - Feature update to Windows 10 (business editions), version 1909, en-gb x64
2020-11-17 14:22:44Z Calculating pre-install reboot requirement...
2020-11-17 14:22:44Z No reboot is pending...
2020-11-17 14:22:44Z Downloading updates...
2020-11-17 14:22:44Z Update (1 of 1) 0d500afc-802b-4b0e-b4cc-4087f87602ff already downloaded, skipping...
2020-11-17 14:22:44Z Installing updates...
2020-11-17 14:22:44Z Creating installer object...
2020-11-17 14:22:44Z Creating install collection...
2020-11-17 14:22:44Z Adding update 0d500afc-802b-4b0e-b4cc-4087f87602ff
2020-11-17 14:22:44Z Update (1 of 1) 0d500afc-802b-4b0e-b4cc-4087f87602ff succeeded
2020-11-17 14:22:44Z Performing post-install reboot requirement check...
2020-11-17 14:22:44Z Return value:
{
    "updates":  {
                    "0d500afc-802b-4b0e-b4cc-4087f87602ff":  {
                                                                 "id":  "0d500afc-802b-4b0e-b4cc-4087f87602ff",
                                                                 "title":  "Feature update to Windows 10 (business editions), version 1909, en-gb x64",
                                                                 "categories":  [
                                                                                    "Upgrades",
                                                                                    "Windows 10, version 1903 and later"
                                                                                ],
                                                                 "kb":  [
                                                                            "3012973"
                                                                        ],
                                                                 "installed":  true
                                                             }
                },
    "failed_update_count":  0,
    "found_update_count":  1,
    "changed":  false,
    "reboot_required":  true,
    "installed_update_count":  1,
    "filtered_updates":  {

                         }
}
2020-11-17 14:22:44Z Native job completed with output: 
Name                           Value                                                                                                                                                                                                                                                                        
----                           -----                                                                                                                                                                                                                                                                        
updates                        {0d500afc-802b-4b0e-b4cc-4087f87602ff}                                                                                                                                                                                                                                       
failed_update_count            0                                                                                                                                                                                                                                                                            
found_update_count             1                                                                                                                                                                                                                                                                            
changed                        False                                                                                                                                                                                                                                                                        
reboot_required                True                                                                                                                                                                                                                                                                         
installed_update_count         1                                                                                                                                                                                                                                                                            
filtered_updates               {}                                                                                                                                                                                                                                                                           

2020-11-17 14:25:55Z WUA is available in current logon process, running natively
2020-11-17 14:25:55Z Creating Windows Update session...
2020-11-17 14:25:55Z Create Windows Update searcher...
2020-11-17 14:25:55Z Setting the Windows Update Agent source catalog...
2020-11-17 14:25:55Z Requested search source is 'managed_server'
2020-11-17 14:25:55Z Search source set to 'managed_server' (ServerSelection = 1)
2020-11-17 14:25:55Z Searching for updates to install
2020-11-17 14:25:58Z Found 1 updates
2020-11-17 14:25:58Z Creating update collection...
2020-11-17 14:25:58Z Adding update 0d500afc-802b-4b0e-b4cc-4087f87602ff - Feature update to Windows 10 (business editions), version 1909, en-gb x64
2020-11-17 14:25:58Z Calculating pre-install reboot requirement...
2020-11-17 14:25:58Z No reboot is pending...
2020-11-17 14:25:58Z Downloading updates...
2020-11-17 14:25:58Z Update (1 of 1) 0d500afc-802b-4b0e-b4cc-4087f87602ff already downloaded, skipping...
2020-11-17 14:25:58Z Installing updates...
2020-11-17 14:25:58Z Creating installer object...
2020-11-17 14:25:58Z Creating install collection...
2020-11-17 14:25:58Z Adding update 0d500afc-802b-4b0e-b4cc-4087f87602ff
2020-11-17 14:25:58Z Update (1 of 1) 0d500afc-802b-4b0e-b4cc-4087f87602ff succeeded
2020-11-17 14:25:58Z Performing post-install reboot requirement check...
2020-11-17 14:25:58Z Return value:
{
    "updates":  {
                    "0d500afc-802b-4b0e-b4cc-4087f87602ff":  {
                                                                 "id":  "0d500afc-802b-4b0e-b4cc-4087f87602ff",
                                                                 "title":  "Feature update to Windows 10 (business editions), version 1909, en-gb x64",
                                                                 "categories":  [
                                                                                    "Upgrades",
                                                                                    "Windows 10, version 1903 and later"
                                                                                ],
                                                                 "kb":  [
                                                                            "3012973"
                                                                        ],
                                                                 "installed":  true
                                                             }
                },
    "failed_update_count":  0,
    "found_update_count":  1,
    "changed":  false,
    "reboot_required":  true,
    "installed_update_count":  1,
    "filtered_updates":  {

                         }
}
2020-11-17 14:25:58Z Native job completed with output: 
Name                           Value                                                                                                                                                                                                                                                                        
----                           -----                                                                                                                                                                                                                                                                        
updates                        {0d500afc-802b-4b0e-b4cc-4087f87602ff}                                                                                                                                                                                                                                       
failed_update_count            0                                                                                                                                                                                                                                                                            
found_update_count             1                                                                                                                                                                                                                                                                            
changed                        False                                                                                                                                                                                                                                                                        
reboot_required                True                                                                                                                                                                                                                                                                         
installed_update_count         1                                                                                                                                                                                                                                                                            
filtered_updates               {}                                                                                                                                                                                                                                                                           

Other info

Interestingly, when checking for updates manually on that system, I see the feature update is indeed ready to install, and indeed pending restart (seems I cannot upload images, so simply copying the main message):

"Restart required. This update is ready to install! We need your help deciding when to restart so we can finish."

EDIT: When manually initiating the feature update from the above screen, the feature update gets applied correctly. The problem seems to be that ansible somehow is not able to properly initiate the feature update.

Is there any other information I can gather to help debug this?

hamannju commented 3 years ago

I just had the problem described here. New Windows Server 2019 Core VM. Installed virtio, openssh, etc. and then I tried using ansible to apply updates:

- hosts: all
  gather_facts: false
  tasks:
    - name: Check for missing updates
      win_updates:
        state: searched
      register: update_count

    - name: Debug
      debug: var=update_count

    - name: Install Updates
      ansible.windows.win_updates:
        state: installed
        reboot: yes
        reboot_timeout: 3600
      register: wsupdates

    - name: Debug
      debug: var=wsupdates

This code got stuck rebooting endlessly. However when I aborted ansible and went into the VM manually with PowerShell I noticed the following: The VM HDD size was set to 32GB and the update was rather large (15 GB cumulative update). So I tried manually applying it using Get-WindowsUpdate -Install and this failed too. Then I setup the VM from scratch and allocated 60GB and lo and behold it just works with the same code. It looks like ansible is not taking into account that applying the update actually uses disk space and can fail. This is just answered with a restart and this then goes on infinitely.

johnbui423 commented 3 years ago

@hamannju - thank you for your comment. Sadly in my case it does not seem to be related to disk space. I added 50GB of additional space, and it did not make a difference. Also, manually installing the feature update works (even with the original disk space).

chrisred commented 3 years ago

I had this issue too.

Ansible 2.9.15 Updating Server 2019 1809 from a fresh install.

The installation of selected updates was completed, but as the original post says reboot_required is never cleared.

Ansible kept rebooting the server until I went to the Windows Update section in the Settings GUI where it showed "Install Pending" for all the updates. Clicking "Install Updates" ran the normal install process and that stopped the reboot loop. reboot_required was now false.

Ansible had installed the updates that were selected (you could see them installed under Control Panel > Programs > Updates), but the Windows Update section under Settings showed something different.