Skip to content

Occasional Infinite While Loop Sysprepping Windows Images #8428

@cbrax

Description

@cbrax

Hey Hashicorp!

I'm building Windows Server 2016 Datacenter images using Packer 1.4.4 in an Azure DevOps build pipeline. The majority of the time builds work with no issues and the images are sysprepped per the example provided in your repo: https://github.com/hashicorp/packer/blob/master/examples/azure/windows.json

Recently I've been seeing around 20% of builds get stuck in an infinite loop during sysprep (I'm using the code in the Windows example above to sysprep). The Image State being returned by the query is IMAGE_STATE_SPECIALIZE_RESEAL_TO_OOBE, which appears to require a reboot. It never transitions out of this state, so it just gets stuck.

The code itself is waiting for IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE, and I'm assuming there's no transition from the SPECIALIZE state to the GENERALIZE state, meaning images get stuck in an infinite while loop.

I know this isn't a Packer-specific issue but am hoping for some advice given it's the example provided in the repo for building Windows images. The quick fix would seem to be to modify the line to be:

"while($true) { $imageState = Get-ItemProperty HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup\\State | Select ImageState; Write-Output $imageState.ImageState; if($imageState.ImageState -ne 'IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE' -and $imageState.ImageState -ne 'IMAGE_STATE_SPECIALIZE_RESEAL_TO_OOBE') { Start-Sleep -s 10 } else { break } }"

However, I'm not sure if this change will result in a functional image as documentation about what the difference is between these two states is very hard to find.

Is there any guidance you can offer?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions