{"action":"created","issue":{"url":"https://api.github.com/repos/hashicorp/packer/issues/6799","repository_url":"https://api.github.com/repos/hashicorp/packer","labels_url":"https://api.github.com/repos/hashicorp/packer/issues/6799/labels{/name}","comments_url":"https://api.github.com/repos/hashicorp/packer/issues/6799/comments","events_url":"https://api.github.com/repos/hashicorp/packer/issues/6799/events","html_url":"https://github.com/hashicorp/packer/issues/6799","id":366662128,"node_id":"MDU6SXNzdWUzNjY2NjIxMjg=","number":6799,"title":"windows-restart fails to detect complete restart during Windows Update","user":{"login":"relip","id":308623,"node_id":"MDQ6VXNlcjMwODYyMw==","avatar_url":"https://avatars0.githubusercontent.com/u/308623?v=4","gravatar_id":"","url":"https://api.github.com/users/relip","html_url":"https://github.com/relip","followers_url":"https://api.github.com/users/relip/followers","following_url":"https://api.github.com/users/relip/following{/other_user}","gists_url":"https://api.github.com/users/relip/gists{/gist_id}","starred_url":"https://api.github.com/users/relip/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/relip/subscriptions","organizations_url":"https://api.github.com/users/relip/orgs","repos_url":"https://api.github.com/users/relip/repos","events_url":"https://api.github.com/users/relip/events{/privacy}","received_events_url":"https://api.github.com/users/relip/received_events","type":"User","site_admin":false},"labels":[{"id":33051538,"node_id":"MDU6TGFiZWwzMzA1MTUzOA==","url":"https://api.github.com/repos/hashicorp/packer/labels/bug","name":"bug","color":"f7c6c7","default":true},{"id":240417513,"node_id":"MDU6TGFiZWwyNDA0MTc1MTM=","url":"https://api.github.com/repos/hashicorp/packer/labels/provisioner/powershell","name":"provisioner/powershell","color":"c7def8","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2018-10-04T07:45:12Z","updated_at":"2018-10-10T20:39:03Z","closed_at":null,"author_association":"NONE","body":"**Packer Version**: Packer v1.3.0\r\n**OS**: Running on CentOS 7, the target host is Windows Sever 2012 R2\r\n**Expected Behavior**: windows-restart waits until Windows Update gets finished\r\n**Actual Behavior**: windows-restart consider the machine restarted during the update and lose the connection after the update is done\r\n**Config to Reproduce**:\r\n```json\r\n{\r\n  \"builders\": [\r\n    {\r\n      \"type\": \"googlecompute\",\r\n      \"project_id\": \"{{user `project_id`}}\",\r\n      \"source_image_family\": \"windows-2012-r2\",\r\n      \"disk_size\": \"60\",\r\n      \"machine_type\": \"n1-highcpu-8\",\r\n      \"communicator\": \"winrm\",\r\n      \"winrm_username\": \"packer_user\",\r\n      \"winrm_insecure\": true,\r\n      \"winrm_use_ssl\": true,\r\n      \"metadata\": {\r\n        \"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\\\"}\"\r\n      },\r\n      \"zone\": \"us-central1-c\"\r\n    }\r\n  ],\r\n  \"provisioners\": [\r\n    {\r\n      \"type\": \"powershell\",\r\n      \"inline\": [\r\n          \"Install-WindowsFeature -Name 'Desktop-Experience'\"\r\n      ]\r\n    },\r\n    {\r\n      \"type\": \"windows-restart\"\r\n    },\r\n    {\r\n      \"type\": \"powershell\",\r\n      \"inline\": [\"GCESysPrep -NoShutdown\"]\r\n    }\r\n  ]\r\n}\r\n```\r\n\r\nAfter 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.\r\n\r\nHere's Windows event logs during the build:\r\n\r\n![image](https://user-images.githubusercontent.com/308623/46457836-ae95d900-c7ee-11e8-9fff-50d7e15ff7e7.png)\r\n\r\n- 1074: Restart initiated\r\n- 10148: WinRM service is listening\r\n- 10149: WinRM service is not listening\r\n\r\nthe second and the third 1074 messages were sent by the system.\r\n\r\n![image](https://user-images.githubusercontent.com/308623/46459281-6200cc80-c7f3-11e8-95a5-7e86723e3ba4.png)\r\n\r\nTo 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\\\\RebootPending` 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). "},"comment":{"url":"https://api.github.com/repos/hashicorp/packer/issues/comments/428722899","html_url":"https://github.com/hashicorp/packer/issues/6799#issuecomment-428722899","issue_url":"https://api.github.com/repos/hashicorp/packer/issues/6799","id":428722899,"node_id":"MDEyOklzc3VlQ29tbWVudDQyODcyMjg5OQ==","user":{"login":"SwampDragons","id":1008838,"node_id":"MDQ6VXNlcjEwMDg4Mzg=","avatar_url":"https://avatars2.githubusercontent.com/u/1008838?v=4","gravatar_id":"","url":"https://api.github.com/users/SwampDragons","html_url":"https://github.com/SwampDragons","followers_url":"https://api.github.com/users/SwampDragons/followers","following_url":"https://api.github.com/users/SwampDragons/following{/other_user}","gists_url":"https://api.github.com/users/SwampDragons/gists{/gist_id}","starred_url":"https://api.github.com/users/SwampDragons/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SwampDragons/subscriptions","organizations_url":"https://api.github.com/users/SwampDragons/orgs","repos_url":"https://api.github.com/users/SwampDragons/repos","events_url":"https://api.github.com/users/SwampDragons/events{/privacy}","received_events_url":"https://api.github.com/users/SwampDragons/received_events","type":"User","site_admin":false},"created_at":"2018-10-10T20:39:03Z","updated_at":"2018-10-10T20:39:03Z","author_association":"CONTRIBUTOR","body":"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.\r\n\r\nMany 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.\r\n\r\nTake 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."}}
{"actor":{"display_login":"SwampDragons"}}