Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

windows-restart fails to detect complete restart during Windows Update #6799

Closed
relip opened this issue Oct 4, 2018 · 34 comments
Closed

windows-restart fails to detect complete restart during Windows Update #6799

relip opened this issue Oct 4, 2018 · 34 comments

Comments

@relip
Copy link

relip commented Oct 4, 2018

Packer Version: Packer v1.3.0
OS: Running on CentOS 7, the target host is Windows Sever 2012 R2
Expected Behavior: windows-restart waits until Windows Update gets finished
Actual Behavior: windows-restart consider the machine restarted during the update and lose the connection after the update is done
Config to Reproduce:

{
  "builders": [
    {
      "type": "googlecompute",
      "project_id": "{{user `project_id`}}",
      "source_image_family": "windows-2012-r2",
      "disk_size": "60",
      "machine_type": "n1-highcpu-8",
      "communicator": "winrm",
      "winrm_username": "packer_user",
      "winrm_insecure": true,
      "winrm_use_ssl": true,
      "metadata": {
        "windows-startup-script-cmd": "winrm quickconfig -quiet & net user /add packer_user & net localgroup administrators packer_user /add & winrm set winrm/config/service/auth @{Basic=\"true\"}"
      },
      "zone": "us-central1-c"
    }
  ],
  "provisioners": [
    {
      "type": "powershell",
      "inline": [
          "Install-WindowsFeature -Name 'Desktop-Experience'"
      ]
    },
    {
      "type": "windows-restart"
    },
    {
      "type": "powershell",
      "inline": ["GCESysPrep -NoShutdown"]
    }
  ]
}

After some investigation it looks like WinRM connection opens during the Windows Update, and the update itself triggers a reboot twice more after reboot triggered by a user. This leads windows-restart to successfully connect to the server during the update, then move on to the next step and lose the connection on following reboot.

Here's Windows event logs during the build:

image

  • 1074: Restart initiated
  • 10148: WinRM service is listening
  • 10149: WinRM service is not listening

the second and the third 1074 messages were sent by the system.

image

To work around this issue, put two windows-restart provisioners in a row, one with additional restart_check_command to wait until HKLM:SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing\\PackagePending no longer exist and another one with no extra command line set (actual reboot is already being initiated by Windows Update however but to wait until the final reboot is done).

@azr
Copy link
Contributor

azr commented Oct 4, 2018

Hey @relip, I believe this was fixed in #6792.

Please try a binary from this comment and tell me if it fixes it for you.

@SwampDragons
Copy link
Contributor

Closing as duplicate; if this turns out not to be fixed in 6792, we can reopen :)

@relip
Copy link
Author

relip commented Oct 10, 2018

did some tests -- here's a log with the new version of Packer and ran with PACKER_LOG=1 ./packer1 build -on-error=abort test.json

2018/10/10 05:21:34 [INFO] Packer version: 1.3.2-dev
2018/10/10 05:21:34 Packer Target OS/Arch: linux amd64
2018/10/10 05:21:34 Built with Go Version: go1.11
(omitted)
googlecompute output will be in this color.

2018/10/10 05:21:34 Build debug mode: false
2018/10/10 05:21:34 Force build: false
2018/10/10 05:21:34 On error: abort
2018/10/10 05:21:34 Preparing build: googlecompute
2018/10/10 05:21:34 Waiting on builds to complete...
2018/10/10 05:21:34 Starting build run: googlecompute
2018/10/10 05:21:34 Running builder: googlecompute
2018/10/10 05:21:34 [INFO] (telemetry) Starting builder googlecompute
2018/10/10 05:21:34 packer1: 2018/10/10 05:21:34 [INFO] Requesting Google token via GCE API Default Client Token Source...
2018/10/10 05:21:34 packer1: 2018/10/10 05:21:34 [INFO] Instantiating GCE client...
==> googlecompute: Checking image does not exist...
==> googlecompute: Creating temporary SSH key for instance...
==> googlecompute: Using image: windows-server-2012-r2-dc-v20180911
==> googlecompute: Creating instance...
    googlecompute: Loading zone: us-central1-c
    googlecompute: Loading machine type: n1-highcpu-8
    googlecompute: Requesting instance creation...
    googlecompute: Waiting for creation operation to complete...
    googlecompute: Instance has been created!
==> googlecompute: Creating windows user for instance...
    googlecompute: Waiting for windows password to complete...
    googlecompute: Created password.
==> googlecompute: Waiting for the instance to become running...
    googlecompute: IP:
==> googlecompute: Using winrm communicator to connect:
2018/10/10 05:22:08 packer1: 2018/10/10 05:22:08 Waiting for WinRM, up to timeout: 30m0s
==> googlecompute: Waiting for WinRM to become available...
2018/10/10 05:22:13 packer1: 2018/10/10 05:22:13 [INFO] Attempting WinRM connection...
2018/10/10 05:22:13 packer1: 2018/10/10 05:22:13 [DEBUG] connecting to remote shell using WinRM
2018/10/10 05:22:43 packer1: 2018/10/10 05:22:43 [ERROR] connection error: unknown error Post https://:5986/wsman: dial tcp:5986: i/o timeout
2018/10/10 05:22:43 packer1: 2018/10/10 05:22:43 [ERROR] WinRM connection err: unknown error Post https://:5986/wsman: dial tcp
:5986: i/o timeout
2018/10/10 05:22:48 packer1: 2018/10/10 05:22:48 [INFO] Attempting WinRM connection...
2018/10/10 05:22:48 packer1: 2018/10/10 05:22:48 [DEBUG] connecting to remote shell using WinRM
2018/10/10 05:23:18 packer1: 2018/10/10 05:23:18 [ERROR] connection error: unknown error Post https://:5986/wsman: dial tcp 35.
226.109.118:5986: i/o timeout
2018/10/10 05:23:18 packer1: 2018/10/10 05:23:18 [ERROR] WinRM connection err: unknown error Post https://:5986/wsman: dial tcp
:5986: i/o timeout
2018/10/10 05:23:23 packer1: 2018/10/10 05:23:23 [INFO] Attempting WinRM connection...
2018/10/10 05:23:23 packer1: 2018/10/10 05:23:23 [DEBUG] connecting to remote shell using WinRM
2018/10/10 05:23:24 packer1: 2018/10/10 05:23:24 [ERROR] connection error: http response error: 401 - invalid content type
2018/10/10 05:23:24 packer1: 2018/10/10 05:23:24 [ERROR] WinRM connection err: http response error: 401 - invalid content type
2018/10/10 05:23:29 packer1: 2018/10/10 05:23:29 [INFO] Attempting WinRM connection...
2018/10/10 05:23:29 packer1: 2018/10/10 05:23:29 [DEBUG] connecting to remote shell using WinRM
2018/10/10 05:23:35 packer1: 2018/10/10 05:23:35 Checking that WinRM is connected with: 'powershell.exe -EncodedCommand aQBmACAAKABUAGUAcwB0A
C0AUABhAHQAaAAgAHYAYQByAGkAYQBiAGwAZQA6AGcAbABvAGIAYQBsADoAUAByAG8AZwByAGUAcwBzAFAAcgBlAGYAZQByAGUAbgBjAGUAKQB7ACQAUAByAG8AZwByAGUAcwBzAFAAcg
BlAGYAZQByAGUAbgBjAGUAPQAnAFMAaQBsAGUAbgB0AGwAeQBDAG8AbgB0AGkAbgB1AGUAJwB9ADsAIABlAGMAaABvACAAIgBXAGkAbgBSAE0AIABjAG8AbgBuAGUAYwB0AGUAZAAuACI
A'
2018/10/10 05:23:35 packer1: 2018/10/10 05:23:35 [INFO] starting remote command: powershell.exe -EncodedCommand aQBmACAAKABUAGUAcwB0AC0AUABhA
HQAaAAgAHYAYQByAGkAYQBiAGwAZQA6AGcAbABvAGIAYQBsADoAUAByAG8AZwByAGUAcwBzAFAAcgBlAGYAZQByAGUAbgBjAGUAKQB7ACQAUAByAG8AZwByAGUAcwBzAFAAcgBlAGYAZQ
ByAGUAbgBjAGUAPQAnAFMAaQBsAGUAbgB0AGwAeQBDAG8AbgB0AGkAbgB1AGUAJwB9ADsAIABlAGMAaABvACAAIgBXAGkAbgBSAE0AIABjAG8AbgBuAGUAYwB0AGUAZAAuACIA
2018/10/10 05:23:36 packer1: 2018/10/10 05:23:36 [INFO] command 'powershell.exe -EncodedCommand aQBmACAAKABUAGUAcwB0AC0AUABhAHQAaAAgAHYAYQByA
GkAYQBiAGwAZQA6AGcAbABvAGIAYQBsADoAUAByAG8AZwByAGUAcwBzAFAAcgBlAGYAZQByAGUAbgBjAGUAKQB7ACQAUAByAG8AZwByAGUAcwBzAFAAcgBlAGYAZQByAGUAbgBjAGUAPQ
AnAFMAaQBsAGUAbgB0AGwAeQBDAG8AbgB0AGkAbgB1AGUAJwB9ADsAIABlAGMAaABvACAAIgBXAGkAbgBSAE0AIABjAG8AbgBuAGUAYwB0AGUAZAAuACIA' exited with code: 0
    googlecompute: WinRM connected.
    googlecompute: #< CLIXML
2018/10/10 05:23:36 packer1: 2018/10/10 05:23:36 Connected to machine
2018/10/10 05:23:36 packer1: 2018/10/10 05:23:36 Running the provision hook
2018/10/10 05:23:36 [INFO] (telemetry) Starting provisioner powershell
    googlecompute: <Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><Obj S="progress" RefId="0"><TN RefId="0">
<T>System.Management.Automation.PSCustomObject</T><T>System.Object</T></TN><MS><I64 N="SourceId">1</I64><PR N="Record"><AV>Preparing modules
for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj><Obj S="progress" RefId="1"><T
NRef RefId="0" /><MS><I64 N="SourceId">1</I64><PR N="Record"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC>
<T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj></Objs>
==> googlecompute: Connected to WinRM!
==> googlecompute: Provisioning with Powershell...
2018/10/10 05:23:36 packer1: 2018/10/10 05:23:36 Found command: Install-WindowsFeature -Name 'Desktop-Experience'
==> googlecompute: Provisioning with powershell script: /tmp/packer-powershell-provisioner437445456
2018/10/10 05:23:36 packer1: 2018/10/10 05:23:36 Opening /tmp/packer-powershell-provisioner437445456 for reading
2018/10/10 05:23:36 packer1: 2018/10/10 05:23:36 Uploading env vars to c:/Windows/Temp/packer-ps-env-vars-5bbd8c5e-7847-5512-69d1-3e10fb7b145
8.ps1
2018/10/10 05:23:36 packer1: 2018/10/10 05:23:36 [INFO] 82 bytes written for 'uploadData'
2018/10/10 05:23:36 [INFO] 82 bytes written for 'uploadData'
2018/10/10 05:23:36 packer1: 2018/10/10 05:23:36 Uploading file to 'c:/Windows/Temp/packer-ps-env-vars-5bbd8c5e-7847-5512-69d1-3e10fb7b1458.p
s1'
2018/10/10 05:23:38 packer1: #< CLIXML
2018/10/10 05:23:39 packer1: <Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><Obj S="progress" RefId="0"><TN
RefId="0"><T>System.Management.Automation.PSCustomObject</T><T>System.Object</T></TN><MS><I64 N="SourceId">1</I64><PR N="Record"><AV>Preparin
g modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj></Objs>#< CLIXML
2018/10/10 05:23:39 packer1: 2018/10/10 05:23:39 [INFO] 50 bytes written for 'uploadData'
2018/10/10 05:23:39 [INFO] 50 bytes written for 'uploadData'
2018/10/10 05:23:39 packer1: <Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><Obj S="progress" RefId="0"><TN
RefId="0"><T>System.Management.Automation.PSCustomObject</T><T>System.Object</T></TN><MS><I64 N="SourceId">1</I64><PR N="Record"><AV>Preparin
g modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj></Objs>2018/10/10 05
:23:39 Uploading file to 'c:/Windows/Temp/script-5bbd8c5e-db7a-cda1-3c86-57fc572acf56.ps1'
2018/10/10 05:23:41 packer1: #< CLIXML
2018/10/10 05:23:42 packer1: <Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><Obj S="progress" RefId="0"><TN
RefId="0"><T>System.Management.Automation.PSCustomObject</T><T>System.Object</T></TN><MS><I64 N="SourceId">1</I64><PR N="Record"><AV>Preparin
g modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj></Objs>#< CLIXML
2018/10/10 05:23:42 packer1: <Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><Obj S="progress" RefId="0"><TN
RefId="0"><T>System.Management.Automation.PSCustomObject</T><T>System.Object</T></TN><MS><I64 N="SourceId">1</I64><PR N="Record"><AV>Preparin
g modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj></Objs>2018/10/10 05
:23:42 [INFO] starting remote command: powershell -executionpolicy bypass "& { if (Test-Path variable:global:ProgressPreference){$ProgressPre
ference='SilentlyContinue'};. c:/Windows/Temp/packer-ps-env-vars-5bbd8c5e-7847-5512-69d1-3e10fb7b1458.ps1; &'c:/Windows/Temp/script-5bbd8c5e-
db7a-cda1-3c86-57fc572acf56.ps1';exit $LastExitCode }"
2018/10/10 05:25:17 packer1: 2018/10/10 05:25:17 [INFO] command 'powershell -executionpolicy bypass "& { if (Test-Path variable:global:Progre
ssPreference){$ProgressPreference='SilentlyContinue'};. c:/Windows/Temp/packer-ps-env-vars-5bbd8c5e-7847-5512-69d1-3e10fb7b1458.ps1; &'c:/Win
dows/Temp/script-5bbd8c5e-db7a-cda1-3c86-57fc572acf56.ps1';exit $LastExitCode }"' exited with code: 0
2018/10/10 05:25:17 packer1: 2018/10/10 05:25:17 [INFO] RPC endpoint: Communicator ended with: 0
    googlecompute:
2018/10/10 05:25:17 [INFO] 0 bytes written for 'stderr'
2018/10/10 05:25:17 [INFO] 319 bytes written for 'stdout'
2018/10/10 05:25:17 [INFO] RPC client: Communicator ended with: 0
2018/10/10 05:25:17 [INFO] RPC endpoint: Communicator ended with: 0
2018/10/10 05:25:17 packer1: 2018/10/10 05:25:17 [INFO] 319 bytes written for 'stdout'
2018/10/10 05:25:17 packer1: 2018/10/10 05:25:17 [INFO] 0 bytes written for 'stderr'
2018/10/10 05:25:17 packer1: 2018/10/10 05:25:17 [INFO] RPC client: Communicator ended with: 0
    googlecompute: Success Restart Needed Exit Code      Feature Result
    googlecompute: ------- -------------- ---------      --------------
    googlecompute: True    Yes            SuccessRest... {Desktop Experience, Ink and Handwriti...
    googlecompute: WARNING: You must restart this server to finish the installation process.
2018/10/10 05:25:17 [INFO] (telemetry) ending powershell
2018/10/10 05:25:17 [INFO] (telemetry) Starting provisioner windows-restart
==> googlecompute: Restarting Machine
2018/10/10 05:25:18 packer1: 2018/10/10 05:25:18 [INFO] starting remote command: shutdown /r /f /t 0 /c "packer restart"
2018/10/10 05:25:18 packer1: 2018/10/10 05:25:18 [INFO] command 'shutdown /r /f /t 0 /c "packer restart"' exited with code: 0
2018/10/10 05:25:18 packer1: 2018/10/10 05:25:18 [INFO] RPC endpoint: Communicator ended with: 0
2018/10/10 05:25:18 [INFO] 0 bytes written for 'stdout'
2018/10/10 05:25:18 [INFO] 0 bytes written for 'stderr'
2018/10/10 05:25:18 [INFO] RPC client: Communicator ended with: 0
2018/10/10 05:25:18 [INFO] RPC endpoint: Communicator ended with: 0
2018/10/10 05:25:18 packer1: 2018/10/10 05:25:18 [INFO] 0 bytes written for 'stdout'
2018/10/10 05:25:18 packer1: 2018/10/10 05:25:18 [INFO] 0 bytes written for 'stderr'
2018/10/10 05:25:18 packer1: 2018/10/10 05:25:18 [INFO] RPC client: Communicator ended with: 0
==> googlecompute: Waiting for machine to restart...
2018/10/10 05:25:19 packer1: 2018/10/10 05:25:19 Check if machine is rebooting...
2018/10/10 05:25:19 packer1: 2018/10/10 05:25:19 [INFO] starting remote command: shutdown /r /f /t 60 /c "packer restart test"
2018/10/10 05:25:19 packer1: 2018/10/10 05:25:19 [INFO] command 'shutdown /r /f /t 60 /c "packer restart test"' exited with code: 1115
2018/10/10 05:25:19 [INFO] 0 bytes written for 'stdout'
2018/10/10 05:25:19 [INFO] 40 bytes written for 'stderr'
2018/10/10 05:25:19 [INFO] RPC client: Communicator ended with: 1115
2018/10/10 05:25:19 packer1: 2018/10/10 05:25:19 [INFO] RPC endpoint: Communicator ended with: 1115
2018/10/10 05:25:19 [INFO] RPC endpoint: Communicator ended with: 1115
2018/10/10 05:25:19 packer1: 2018/10/10 05:25:19 [INFO] 0 bytes written for 'stdout'
2018/10/10 05:25:19 packer1: 2018/10/10 05:25:19 [INFO] 40 bytes written for 'stderr'
2018/10/10 05:25:19 packer1: 2018/10/10 05:25:19 [INFO] RPC client: Communicator ended with: 1115
    googlecompute: A system shutdown is in progress.(1115)
2018/10/10 05:25:19 packer1: 2018/10/10 05:25:19 Reboot already in progress, waiting...
2018/10/10 05:25:29 packer1: 2018/10/10 05:25:29 Check if machine is rebooting...
2018/10/10 05:25:30 packer1: 2018/10/10 05:25:30 [INFO] starting remote command: shutdown /r /f /t 60 /c "packer restart test"
2018/10/10 05:25:30 packer1: 2018/10/10 05:25:30 [INFO] command 'shutdown /r /f /t 60 /c "packer restart test"' exited with code: 1115
2018/10/10 05:25:30 [INFO] 0 bytes written for 'stdout'
2018/10/10 05:25:30 [INFO] 40 bytes written for 'stderr'
2018/10/10 05:25:30 packer1: 2018/10/10 05:25:30 [INFO] RPC endpoint: Communicator ended with: 1115
2018/10/10 05:25:30 [INFO] RPC client: Communicator ended with: 1115
2018/10/10 05:25:30 [INFO] RPC endpoint: Communicator ended with: 1115
2018/10/10 05:25:30 packer1: 2018/10/10 05:25:30 [INFO] 0 bytes written for 'stdout'
2018/10/10 05:25:30 packer1: 2018/10/10 05:25:30 [INFO] 40 bytes written for 'stderr'
2018/10/10 05:25:30 packer1: 2018/10/10 05:25:30 [INFO] RPC client: Communicator ended with: 1115
    googlecompute: A system shutdown is in progress.(1115)
2018/10/10 05:25:30 packer1: 2018/10/10 05:25:30 Reboot already in progress, waiting...
2018/10/10 05:25:40 packer1: 2018/10/10 05:25:40 Check if machine is rebooting...
2018/10/10 05:25:40 packer1: 2018/10/10 05:25:40 [INFO] starting remote command: shutdown /r /f /t 60 /c "packer restart test"
    googlecompute: A system shutdown is in progress.(1115)
2018/10/10 05:25:40 packer1: 2018/10/10 05:25:40 [INFO] command 'shutdown /r /f /t 60 /c "packer restart test"' exited with code: 1115
2018/10/10 05:25:40 packer1: 2018/10/10 05:25:40 [INFO] RPC endpoint: Communicator ended with: 1115
2018/10/10 05:25:40 [INFO] 0 bytes written for 'stdout'
2018/10/10 05:25:40 [INFO] 40 bytes written for 'stderr'
2018/10/10 05:25:40 [INFO] RPC client: Communicator ended with: 1115
2018/10/10 05:25:40 [INFO] RPC endpoint: Communicator ended with: 1115
2018/10/10 05:25:40 packer1: 2018/10/10 05:25:40 [INFO] 0 bytes written for 'stdout'
2018/10/10 05:25:40 packer1: 2018/10/10 05:25:40 [INFO] 40 bytes written for 'stderr'
2018/10/10 05:25:40 packer1: 2018/10/10 05:25:40 [INFO] RPC client: Communicator ended with: 1115
2018/10/10 05:25:40 packer1: 2018/10/10 05:25:40 Reboot already in progress, waiting...
2018/10/10 05:25:50 packer1: 2018/10/10 05:25:50 Check if machine is rebooting...
2018/10/10 05:25:51 packer1: 2018/10/10 05:25:51 [INFO] starting remote command: shutdown /r /f /t 60 /c "packer restart test"
2018/10/10 05:25:51 packer1: 2018/10/10 05:25:51 [INFO] command 'shutdown /r /f /t 60 /c "packer restart test"' exited with code: 1115
2018/10/10 05:25:51 packer1: 2018/10/10 05:25:51 [INFO] RPC endpoint: Communicator ended with: 1115
2018/10/10 05:25:51 [INFO] 0 bytes written for 'stdout'
2018/10/10 05:25:51 [INFO] 40 bytes written for 'stderr'
2018/10/10 05:25:51 [INFO] RPC client: Communicator ended with: 1115
2018/10/10 05:25:51 [INFO] RPC endpoint: Communicator ended with: 1115
    googlecompute: A system shutdown is in progress.(1115)
2018/10/10 05:25:51 packer1: 2018/10/10 05:25:51 [INFO] 0 bytes written for 'stdout'
2018/10/10 05:25:51 packer1: 2018/10/10 05:25:51 [INFO] 40 bytes written for 'stderr'
2018/10/10 05:25:51 packer1: 2018/10/10 05:25:51 [INFO] RPC client: Communicator ended with: 1115
2018/10/10 05:25:51 packer1: 2018/10/10 05:25:51 Reboot already in progress, waiting...
2018/10/10 05:26:01 packer1: 2018/10/10 05:26:01 Check if machine is rebooting...
2018/10/10 05:26:08 [INFO] 0 bytes written for 'stdout'
2018/10/10 05:26:08 [INFO] 0 bytes written for 'stderr'
2018/10/10 05:26:08 packer1: 2018/10/10 05:26:08 [INFO] 0 bytes written for 'stdout'
2018/10/10 05:26:08 packer1: 2018/10/10 05:26:08 Waiting for machine to reboot with timeout: 5m0s
2018/10/10 05:26:08 packer1: 2018/10/10 05:26:08 Waiting for machine to become available...
2018/10/10 05:26:08 packer1: 2018/10/10 05:26:08 Checking that communicator is connected with: 'powershell.exe -EncodedCommand ZQBjAGgAbwAgACIAJAB7AGUAbgB2ADoAQwBPAE0AUABVAFQARQBSAE4AQQBNAEUAfQAgAHIAZQBzAHQAYQByAHQAZQBkAC4AIgA='
2018/10/10 05:26:08 packer1: 2018/10/10 05:26:08 [INFO] 0 bytes written for 'stderr'
2018/10/10 05:26:14 packer1: 2018/10/10 05:26:14 [INFO] starting remote command: powershell.exe -EncodedCommand ZQBjAGgAbwAgACIAJAB7AGUAbgB2ADoAQwBPAE0AUABVAFQARQBSAE4AQQBNAEUAfQAgAHIAZQBzAHQAYQByAHQAZQBkAC4AIgA=
2018/10/10 05:26:17 packer1: 2018/10/10 05:26:17 [INFO] command 'powershell.exe -EncodedCommand ZQBjAGgAbwAgACIAJAB7AGUAbgB2ADoAQwBPAE0AUABVAFQARQBSAE4AQQBNAEUAfQAgAHIAZQBzAHQAYQByAHQAZQBkAC4AIgA=' exited with code: 0
2018/10/10 05:26:17 [INFO] 28 bytes written for 'stdout'
2018/10/10 05:26:17 [INFO] 392 bytes written for 'stderr'
2018/10/10 05:26:17 [INFO] RPC client: Communicator ended with: 0
2018/10/10 05:26:17 [INFO] RPC endpoint: Communicator ended with: 0
2018/10/10 05:26:17 packer1: 2018/10/10 05:26:17 [INFO] RPC endpoint: Communicator ended with: 0
2018/10/10 05:26:17 packer1: 2018/10/10 05:26:17 [INFO] 28 bytes written for 'stdout'
2018/10/10 05:26:17 packer1: 2018/10/10 05:26:17 [INFO] 392 bytes written for 'stderr'
2018/10/10 05:26:17 packer1: 2018/10/10 05:26:17 [INFO] RPC client: Communicator ended with: 0
    googlecompute: PACKER-5BBD8C5E restarted.
    googlecompute: #< CLIXML
    googlecompute: <Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><Obj S="progress" RefId="0"><TN RefId="0"><T>System.Management.Automation.PSCustomObject</T><T>System.Object</T></TN><MS><I64 N="SourceId">1</I64><PR N="Record"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj></Objs>
==> googlecompute: Machine successfully restarted, moving on
2018/10/10 05:26:17 [INFO] (telemetry) ending windows-restart
2018/10/10 05:26:17 [INFO] (telemetry) Starting provisioner powershell
==> googlecompute: Provisioning with Powershell...
2018/10/10 05:26:17 packer1: 2018/10/10 05:26:17 Found command: GCESysprep -Noshutdown
2018/10/10 05:26:17 packer1: 2018/10/10 05:26:17 Found command: exit 1
==> googlecompute: Provisioning with powershell script: /tmp/packer-powershell-provisioner564658929
2018/10/10 05:26:17 packer1: 2018/10/10 05:26:17 Opening /tmp/packer-powershell-provisioner564658929 for reading
2018/10/10 05:26:17 packer1: 2018/10/10 05:26:17 Uploading env vars to c:/Windows/Temp/packer-ps-env-vars-5bbd8c5e-b042-82d1-7b80-73228cc176c3.ps1
2018/10/10 05:26:17 packer1: 2018/10/10 05:26:17 [INFO] 82 bytes written for 'uploadData'
2018/10/10 05:26:17 [INFO] 82 bytes written for 'uploadData'
2018/10/10 05:26:17 packer1: 2018/10/10 05:26:17 Uploading file to 'c:/Windows/Temp/packer-ps-env-vars-5bbd8c5e-b042-82d1-7b80-73228cc176c3.ps1'
2018/10/10 05:26:19 packer1: #< CLIXML
2018/10/10 05:26:19 packer1: <Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><Obj S="progress" RefId="0"><TN RefId="0"><T>System.Management.Automation.PSCustomObject</T><T>System.Object</T></TN><MS><I64 N="SourceId">1</I64><PR N="Record"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj></Objs>#< CLIXML
2018/10/10 05:26:20 packer1: 2018/10/10 05:26:20 [INFO] 30 bytes written for 'uploadData'
2018/10/10 05:26:20 [INFO] 30 bytes written for 'uploadData'
2018/10/10 05:26:20 packer1: <Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><Obj S="progress" RefId="0"><TN RefId="0"><T>System.Management.Automation.PSCustomObject</T><T>System.Object</T></TN><MS><I64 N="SourceId">1</I64><PR N="Record"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj></Objs>2018/10/10 05:26:20 Uploading file to 'c:/Windows/Temp/script-5bbd8c5e-6403-e8cb-4634-75e12d3257ca.ps1'
2018/10/10 05:26:21 packer1: #< CLIXML
2018/10/10 05:26:22 packer1: <Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><Obj S="progress" RefId="0"><TN RefId="0"><T>System.Management.Automation.PSCustomObject</T><T>System.Object</T></TN><MS><I64 N="SourceId">1</I64><PR N="Record"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj></Objs>#< CLIXML
2018/10/10 05:26:22 packer1: <Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><Obj S="progress" RefId="0"><TN RefId="0"><T>System.Management.Automation.PSCustomObject</T><T>System.Object</T></TN><MS><I64 N="SourceId">1</I64><PR N="Record"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj></Objs>2018/10/10 05:26:22 [INFO] starting remote command: powershell -executionpolicy bypass "& { if (Test-Path variable:global:ProgressPreference){$ProgressPreference='SilentlyContinue'};. c:/Windows/Temp/packer-ps-env-vars-5bbd8c5e-b042-82d1-7b80-73228cc176c3.ps1; &'c:/Windows/Temp/script-5bbd8c5e-6403-e8cb-4634-75e12d3257ca.ps1';exit $LastExitCode }"
    googlecompute: 2018/10/10 05:26:23 GCESysprep: Beginning GCESysprep.
    googlecompute: 2018/10/10 05:26:23 GCESysprep: No answer file was specified. Using default file.
    googlecompute: 2018/10/10 05:26:23 GCESysprep: Running 'schtasks' with arguments '/delete /tn GCEStartup /f'
    googlecompute: 2018/10/10 05:26:23 GCESysprep: --> SUCCESS: The scheduled task "GCEStartup" was successfully deleted.
    googlecompute: 2018/10/10 05:26:24 GCESysprep: Clearing events in EventViewer.
2018/10/10 05:26:25 packer1: 2018/10/10 05:26:25 [INFO] command 'powershell -executionpolicy bypass "& { if (Test-Path variable:global:ProgressPreference){$ProgressPreference='SilentlyContinue'};. c:/Windows/Temp/packer-ps-env-vars-5bbd8c5e-b042-82d1-7b80-73228cc176c3.ps1; &'c:/Windows/Temp/script-5bbd8c5e-6403-e8cb-4634-75e12d3257ca.ps1';exit $LastExitCode }"' exited with code: 0
2018/10/10 05:26:25 [INFO] 397 bytes written for 'stdout'
2018/10/10 05:26:25 [INFO] 0 bytes written for 'stderr'
2018/10/10 05:26:25 packer1: 2018/10/10 05:26:25 [INFO] RPC endpoint: Communicator ended with: 0
2018/10/10 05:26:25 [INFO] RPC client: Communicator ended with: 0
2018/10/10 05:26:25 [INFO] RPC endpoint: Communicator ended with: 0
2018/10/10 05:26:25 packer1: 2018/10/10 05:26:25 [INFO] 397 bytes written for 'stdout'
2018/10/10 05:26:25 packer1: 2018/10/10 05:26:25 [INFO] 0 bytes written for 'stderr'
2018/10/10 05:26:25 packer1: 2018/10/10 05:26:25 [INFO] RPC client: Communicator ended with: 0
2018/10/10 05:26:25 [INFO] (telemetry) ending powershell
==> googlecompute: Deleting instance...
    googlecompute: Instance has been deleted!
==> googlecompute: Creating image...

the config is

{
  "builders": [
    {
      "type": "googlecompute",
      "source_image_family": "windows-2012-r2",
      "disk_size": "60",
      "machine_type": "n1-highcpu-8",
      "communicator": "winrm",
      "winrm_username": "packer_user",
      "winrm_insecure": true,
      "winrm_use_ssl": true,
      "metadata": {
        "windows-startup-script-cmd": "winrm quickconfig -quiet & net user /add packer_user & net localgroup administrators packer_user /add & winrm set winrm/config/service/auth @{Basic=\"true\"}"
      },
      "zone": "us-central1-c"
    }
  ],
  "provisioners": [
    {
      "type": "powershell",
      "inline": [
          "Install-WindowsFeature -Name 'Desktop-Experience'"
      ]
    },
    {
      "type": "windows-restart"
    },
    {
      "type": "powershell",
      "inline": [
        "GCESysprep -Noshutdown",
        "exit 1"
      ]
    }
  ]
}

Packer should abort since exit 1 is in the inline commands and -on-error=abort option, however the script returned 0 and deletes the instance. I assume this is because the final reboot was in progress and Windows made forcibly the script to return 0. (also GCESysPrep didn't succeed either)

@relip
Copy link
Author

relip commented Oct 10, 2018

ran another test with just while ($true) { sleep 1; } and it hangs endlessly as expected

googlecompute output will be in this color.

==> googlecompute: Checking image does not exist...
==> googlecompute: Creating temporary SSH key for instance...
==> googlecompute: Using image: windows-server-2012-r2-dc-v20180911
==> googlecompute: Creating instance...
    googlecompute: Loading zone: us-central1-c
    googlecompute: Loading machine type: n1-highcpu-8
    googlecompute: Requesting instance creation...
    googlecompute: Waiting for creation operation to complete...
    googlecompute: Instance has been created!
==> googlecompute: Creating windows user for instance...
    googlecompute: Waiting for windows password to complete...
    googlecompute: Created password.
==> googlecompute: Waiting for the instance to become running...
    googlecompute: IP:
==> googlecompute: Using winrm communicator to connect:
==> googlecompute: Waiting for WinRM to become available...
    googlecompute: WinRM connected.
    googlecompute: #< CLIXML
    googlecompute: <Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><Obj S="progress" RefId="0"><TN RefId="0"><T>System.Management.Automation.PSCustomObject</T><T>System.Object</T></TN><MS><I64 N="SourceId">1</I64><PR N="Record"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj><Obj S="progress" RefId="1"><TNRef RefId="0" /><MS><I64 N="SourceId">1</I64><PR N="Record"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj></Objs>
==> googlecompute: Connected to WinRM!
==> googlecompute: Provisioning with Powershell...
==> googlecompute: Provisioning with powershell script: /tmp/packer-powershell-provisioner751252492
^C==> googlecompute: Deleting instance...
^C    googlecompute: Instance has been deleted!
==> googlecompute: Deleting disk...
    googlecompute: Disk has been deleted!
Build 'googlecompute' finished.
Cleanly cancelled builds after being interrupted.

but with the following provisioners

    {
      "type": "powershell",
      "inline": [
          "Install-WindowsFeature -Name 'Desktop-Experience'"
      ]
    },
    {
      "type": "windows-restart"
    },
    {
      "type": "powershell",
      "inline": [
        "while ($true) { sleep 1; }"
      ]
    }

it exits with exit code 1

==> googlecompute: Checking image does not exist...
==> googlecompute: Creating temporary SSH key for instance...
==> googlecompute: Using image: windows-server-2012-r2-dc-v20180911
==> googlecompute: Creating instance...
    googlecompute: Loading zone: us-central1-c
    googlecompute: Loading machine type: n1-highcpu-8
    googlecompute: Requesting instance creation...
    googlecompute: Waiting for creation operation to complete...
    googlecompute: Instance has been created!
==> googlecompute: Creating windows user for instance...
    googlecompute: Waiting for windows password to complete...
    googlecompute: Created password.
==> googlecompute: Waiting for the instance to become running...
    googlecompute: IP:
==> googlecompute: Using winrm communicator to connect:
==> googlecompute: Waiting for WinRM to become available...
    googlecompute: WinRM connected.
    googlecompute: #< CLIXML
    googlecompute: <Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><Obj S="progress" RefId="0"><TN RefId="0"><T>System.Management.Automation.PSCustomObject</T><T>System.Object</T></TN><MS><I64 N="SourceId">1</I64><PR N="Record"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj><Obj S="progress" RefId="1"><TNRef RefId="0" /><MS><I64 N="SourceId">1</I64><PR N="Record"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj></Objs>
==> googlecompute: Connected to WinRM!
==> googlecompute: Provisioning with Powershell...
==> googlecompute: Provisioning with powershell script: /tmp/packer-powershell-provisioner032816360
    googlecompute:
    googlecompute: Success Restart Needed Exit Code      Feature Result
    googlecompute: ------- -------------- ---------      --------------
    googlecompute: True    Yes            SuccessRest... {Desktop Experience, Ink and Handwriti...
    googlecompute: WARNING: You must restart this server to finish the installation process.
==> googlecompute: Restarting Machine
==> googlecompute: Waiting for machine to restart...
    googlecompute: A system shutdown is in progress.(1115)
    googlecompute: A system shutdown is in progress.(1115)
    googlecompute: A system shutdown is in progress.(1115)
    googlecompute: A system shutdown is in progress.(1115)
    googlecompute: PACKER-5BBD953D restarted.
    googlecompute: #< CLIXML
    googlecompute: <Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04"><Obj S="progress" RefId="0"><TN RefId="0"><T>System.Management.Automation.PSCustomObject</T><T>System.Object</T></TN><MS><I64 N="SourceId">1</I64><PR N="Record"><AV>Preparing modules for first use.</AV><AI>0</AI><Nil /><PI>-1</PI><PC>-1</PC><T>Completed</T><SR>-1</SR><SD> </SD></PR></MS></Obj></Objs>
==> googlecompute: Machine successfully restarted, moving on
==> googlecompute: Provisioning with Powershell...
==> googlecompute: Provisioning with powershell script: /tmp/packer-powershell-provisioner663797057
==> googlecompute: Deleting instance...

@azr @SwampDragons

@SwampDragons
Copy link
Contributor

SwampDragons commented Oct 10, 2018

It sounds to me like this is an issue with the powershell provisioner, not the windows-restart provisioner. the powershell provisioner isn't waiting for the script to return.

@chryzsh
Copy link

chryzsh commented Oct 10, 2018

Hey @SwampDragons I've been having this issue for several days now.I've followed this issue closely, in addition to this #6733 and this rgl/packer-plugin-windows-update#22. I have tried version 1.2.3, 1.2.5, 1.3.1 and the build with the fix posted in the 6733 with the supposed fix, but none of them have fixed my issue. I am not 100 % sure I have the exact same issue, but it sounds very similar. After installing the OS, the provisioner installs windows updates, then reboots. Then I get a pending reboot detected message and it exits with code 259.

I am very happy to help with any testing or debugging this issue as I am eager to get it working. If you need me to attach packerlog.txt or any of my config let me know.

018/10/10 13:10:40 ui: ==> vmware-iso: Machine successfully restarted, moving on
2018/10/10 13:10:40 ui: ==> vmware-iso: Running Windows update...
2018/10/10 13:10:40 packer.exe: 2018/10/10 13:10:40 [INFO] starting remote command: PowerShell -ExecutionPolicy Bypass -OutputFormat Text -File C:/Windows/Temp/packer-windows-update-elevated.ps1
2018/10/10 13:10:51 ui:     vmware-iso: #< CLIXML
2018/10/10 13:10:53 ui:     vmware-iso: Pending Reboot detected. Waiting for the Windows Modules Installer to exit...
2018/10/10 13:13:10 packer.exe: 2018/10/10 13:13:10 [INFO] command 'PowerShell -ExecutionPolicy Bypass -OutputFormat Text -File C:/Windows/Temp/packer-windows-update-elevated.ps1' exited with code: 259```

@relip
Copy link
Author

relip commented Oct 10, 2018

It is related to the restart provisioner and the reason the powershell provisioner got an exit code is that the Windows focibly made the script to exit because rebooting was ongoing as I wrote above 🙂

@SwampDragons
Copy link
Contributor

@relip is your Powershell provisioner telling the machine to reboot?

@SwampDragons
Copy link
Contributor

I believe you both are running into a known issue -- essentially, our winrm communicator isn't good at handling windows restarts. This is the entire reason we have the windows-restart provisioner; the powershell provisioner can't recover from the disconnection that happens when you restart windows.

Many newer users find this frustrating because it means they can't run windows update from within a powershell provisioner; however, if you check out some of the community-based windows projects, you'll see that this can be worked around by running your windows update script as a floppy file, before the provisioning begins.

Take a look at https://github.com/joefitzgerald/packer-windows/blob/master/windows_2012_r2.json#L82 for an example of where you'd handle this in your Packer config.

@SwampDragons
Copy link
Contributor

To clarify: Packer will basically always break if you try to initiate a restart from the powershell provisioner, instead of initiating the restart from the windows-restart provisioner.

@chryzsh
Copy link

chryzsh commented Oct 10, 2018

I do use the windows-restart provisioner. I have also tried doing windows updates during sysprep which didn't work. Exits with code 259.

@SwampDragons
Copy link
Contributor

@chryzsh Can you share your config? The more information I have the easier this will be to debug.

@SwampDragons
Copy link
Contributor

I think I'm missing something in #6799 (comment) -- what combination of provisioners produces the first log excerpt you shared?

@relip
Copy link
Author

relip commented Oct 11, 2018

@SwampDragons please see the first thread again #6799 (comment) all of this happened because Windows itself reboots two times after installing Windows Feature then reboot the system, and #6799 (comment) is to back up this comment #6799 (comment).

To recap:

  1. Install a Windows Feature
  2. Reboot using windows-restart
  3. The system reboots (triggered by me) and enters into the Windows Update session
  4. Windows does their stuff (I don't know what's going on exactly)
  5. The system reboots (it triggered by the system)
  6. The system once again enters into the Windows Update session
  7. Windows does their stuff again
  8. The system reboots (it also triggered by the system)
  9. Finally the system enters into a normal session

The windows-restart tries to reconnect to the system in 4th stage which will soon to be rebooted again and consequentially connection drops and Packer fails.

@chryzsh
Copy link

chryzsh commented Oct 11, 2018

@chryzsh Can you share your config? The more information I have the easier this will be to debug.

Yes of course. I changed the extension to .txt to be able to upload them. I attached the powershell script for enabling WinRM that does appear to work just fine. But as you said earlier, I am fairly sure that when windows reboots automatically after installing the first round of updates the WinRM connection drops and isn't properly restored. It's either that or something wrong with how it handles pending reboots. I don't think my build ever gets to the windows-restart provisioner because windows reboots itself immediately after updates.

s2016.txt
Set-WinRM.txt

@SwampDragons SwampDragons removed the bug label Oct 11, 2018
@SwampDragons
Copy link
Contributor

@relip I'm sorry that this back and forth has gotten complicated and involved repetition. I suspect you're getting frustrated and I'm sorry for that. Text-based communication is often slow and confusing, especially when people end up talking in multiple threads. I really appreciate your recap. I was initially treating this issue as a new bug rather than as a known issue with known workarounds, and that caused me to interact weirdly on it for a while.

Sorry for the incoming wall of text; I just want to give as much context as I can.

tl;dr: What you're experiencing now is known, and the long-recommended workaround is to do all of your windows updates in sysprep, before winRM is connected, so that the provisioners don't get confused by all of the extraneous reboots that windows updates cause.

BUT: I really love your workaround with the registry key and want to implement it

Longer explanation:

What I was trying to say here:

To clarify: Packer will basically always break if you try to initiate a restart from the powershell provisioner, instead of initiating the restart from the windows-restart provisioner.

is that any reboot that isn't initiated and completed by the windows-restart provisioner will cause issues. This includes reboots initiated by Windows itself. I probably shouldn't have used the phrase "powershell" because that seems to have caused confusion. It doesn't matter if you directly call for a restart from a powershell provisioner or if a restart happens as a side effect of another system call (in your case, the installation of the windows feature). You are performing an action that initiates a reboot, separately from the windows-restart provisioner, and it's a known issue that Packer doesn't handle this well.

The windows-restart provisioner just performs a single disconnect and reconnect. It sounds to me like you're expecting it to do more than that. You want it to actually wait for several reboots in a row, some of which it didn't initiate. This isn't how the provisioner was designed, so it's not surprising to me that the provisioner isn't working for you.

All of this said, I really like your workaround with the windows-restart provisioners, adding a restart-check that actually looks for the registry key HKLM:SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing\\RebootPending

It's the first time I've seen someone use this workaround, and it's definitely more flexible than the route of forcing all updates to happen in Sysprep.

I'll see if I can add a flag that will tell the restart provisioner to check this key, so that you don't need to run it twice. Would that be an acceptable resolution for you?

Again, I'm sorry for the frustration here. Hopefully now we're on the same page and we can move forward.

@rgl
Copy link
Contributor

rgl commented Oct 14, 2018

Regarding the windows-update provisioner, as-of 0.6.0, it now also sets the restart_check_command to run this snippet:

https://github.com/rgl/packer-provisioner-windows-update/blob/39e3253e91d68bf8343600375936af30275aaaf0/update/windows-update.ps1#L104-L123

And it seems to do the trick while the machine is rebooting after an update (which sometimes needs more than one reboot). I'm not checking for the mentioned RebootPending key, instead I'm checking whether there no more updates pending and I'm waiting for TiWorker.exe to end before continuing.

@SwampDragons
Copy link
Contributor

@rgl thanks! I'll take a look and see if it makes sense for us to incorporate some of your restart_check_command stuff.

@SwampDragons
Copy link
Contributor

@relip I wasn't able to get a check against that registry key to solve your use case. Can you share the specialized check command you're sending"

@relip
Copy link
Author

relip commented Oct 26, 2018

@SwampDragons Sorry I was on vacation since then, saw this comment just now. Having that kind of option would be really appreciated!

For the registry key I was looking at different test script at that time -- the key that actually changed was HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\PackagePending. Sorry for the confusion. (Also edited the first thread to PackagePending to avoid confusion.)

@SwampDragons
Copy link
Contributor

@relip I hope you had an awesome vacation :) . I'll take a look at whether I can repro using that key. Thanks.

@SwampDragons
Copy link
Contributor

I've made a PR to try to incorporate a registry check into the windows-restart provisioner. I'm struggling at the moment to reproduce this; if anyone wants to give it a try with their real-life use case while I'm getting a reliable repro case set up I'd appreciate the help:

linux build:
packer.zip

osx build:
packer.zip

windows build:
packer.zip

@relip
Copy link
Author

relip commented Dec 6, 2018

@SwampDragons just tested the build and it doesn't work (sysprep was running during the reboot phase) -- saw the code and looks like it doesn't check PackagePending but RebootPending?

@SwampDragons
Copy link
Contributor

Ah! good catch. I swear I read it 5 times. I'll push an update.

@SwampDragons
Copy link
Contributor

Can you try this one?

linux:
packer.zip

osx:
packer.zip

windows:
packer.zip

@SwampDragons
Copy link
Contributor

Okay, let's try this one more time post- @relip's fix.

windows:
packer.zip

osx:
packer.zip

linux:
packer.zip

@relip
Copy link
Author

relip commented Dec 11, 2018

@SwampDragons Thanks for the update!

Just tested on our actual deployment config and got into infinite loop on checking HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Services\Pending

To check things I RDPed into the node and the key was still there even though the rebooting process is finished. I'm not sure what it is and couldn't find exact information of the registry key/entry but still I can say it is clear that the key does not represent the current state (which requires a reboot or not). I think it's okay to remove the key?

image

image

These keys/entries were still there even I rebooted the node multiple after the reboot initiated by Packer.

@SwampDragons
Copy link
Contributor

Definitely. I'll remove, and also add a flag to the provisioner so users can provide their own.

@SwampDragons
Copy link
Contributor

windows: packer.zip

osx:
packer.zip

linux:
packer.zip

@relip
Copy link
Author

relip commented Dec 12, 2018

Seems like it works?

@SwampDragons
Copy link
Contributor

🎉

I'll run a few more sanity tests and then merge.

@theodoregoetz
Copy link

theodoregoetz commented Dec 21, 2018

I can confirm that this works with a Windows 10 guest using Virtual Box 5.2 on a Fedora 29 host. Thank you!

@SwampDragons
Copy link
Contributor

I think we can count this as addressed now that #7056 is merged.

@ghost
Copy link

ghost commented Mar 30, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Mar 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants