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

Deprovisioning failures #38

Open
WaitingForGuacamole opened this issue Jul 9, 2022 · 2 comments
Open

Deprovisioning failures #38

WaitingForGuacamole opened this issue Jul 9, 2022 · 2 comments

Comments

@WaitingForGuacamole
Copy link

I'm getting the following error in the deprovisioning phase of my Windows image:

[0ca7f19d-2eb3-4405-a951-1f0fe5139a0d] PACKER OUT     azure-arm: Write-Output '>>> Waiting for GA Service (RdAgent) to start ...'
[0ca7f19d-2eb3-4405-a951-1f0fe5139a0d] PACKER OUT     azure-arm: while ((Get-Service RdAgent).Status -ne 'Running') { Start-Sleep -s 5 }
[0ca7f19d-2eb3-4405-a951-1f0fe5139a0d] PACKER OUT     azure-arm: Write-Output '>>> Waiting for GA Service (WindowsAzureTelemetryService) to start ...'
[0ca7f19d-2eb3-4405-a951-1f0fe5139a0d] PACKER OUT     azure-arm: while ((Get-Service WindowsAzureTelemetryService) -and ((Get-Service WindowsAzureTelemetryService).Status -ne 'Running')) { Start-Sleep -s 5 }
[0ca7f19d-2eb3-4405-a951-1f0fe5139a0d] PACKER OUT     azure-arm: Write-Output '>>> Waiting for GA Service (WindowsAzureGuestAgent) to start ...'
[0ca7f19d-2eb3-4405-a951-1f0fe5139a0d] PACKER OUT     azure-arm: while ((Get-Service WindowsAzureGuestAgent).Status -ne 'Running') { Start-Sleep -s 5 }
[0ca7f19d-2eb3-4405-a951-1f0fe5139a0d] PACKER OUT     azure-arm: Write-Output '>>> Sysprepping VM ...'
[0ca7f19d-2eb3-4405-a951-1f0fe5139a0d] PACKER OUT     azure-arm: if( Test-Path $Env:SystemRoot\system32\Sysprep\unattend.xml ) {
[0ca7f19d-2eb3-4405-a951-1f0fe5139a0d] PACKER OUT     azure-arm:   Remove-Item $Env:SystemRoot\system32\Sysprep\unattend.xml -Force
[0ca7f19d-2eb3-4405-a951-1f0fe5139a0d] PACKER OUT     azure-arm: }
[0ca7f19d-2eb3-4405-a951-1f0fe5139a0d] PACKER OUT     azure-arm: & $Env:SystemRoot\System32\Sysprep\Sysprep.exe /oobe /generalize /quiet /quit
[0ca7f19d-2eb3-4405-a951-1f0fe5139a0d] PACKER OUT     azure-arm: while($true) {
[0ca7f19d-2eb3-4405-a951-1f0fe5139a0d] PACKER OUT     azure-arm:   $imageState = (Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\State).ImageState
[0ca7f19d-2eb3-4405-a951-1f0fe5139a0d] PACKER OUT     azure-arm:   Write-Output $imageState
[0ca7f19d-2eb3-4405-a951-1f0fe5139a0d] PACKER OUT     azure-arm:   if ($imageState -eq 'IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE') { break }
[0ca7f19d-2eb3-4405-a951-1f0fe5139a0d] PACKER OUT     azure-arm:   Start-Sleep -s 5
[0ca7f19d-2eb3-4405-a951-1f0fe5139a0d] PACKER OUT     azure-arm: }
[0ca7f19d-2eb3-4405-a951-1f0fe5139a0d] PACKER OUT     azure-arm: Write-Output '>>> Sysprep complete ...'
[0ca7f19d-2eb3-4405-a951-1f0fe5139a0d] PACKER OUT     azure-arm: >>> Waiting for GA Service (RdAgent) to start ...
[0ca7f19d-2eb3-4405-a951-1f0fe5139a0d] PACKER OUT     azure-arm: >>> Waiting for GA Service (WindowsAzureTelemetryService) to start ...
[0ca7f19d-2eb3-4405-a951-1f0fe5139a0d] PACKER OUT     azure-arm: >>> Waiting for GA Service (WindowsAzureGuestAgent) to start ...
[0ca7f19d-2eb3-4405-a951-1f0fe5139a0d] PACKER OUT     azure-arm: >>> Sysprepping VM ...
[0ca7f19d-2eb3-4405-a951-1f0fe5139a0d] PACKER OUT     azure-arm: IMAGE_STATE_COMPLETE
[0ca7f19d-2eb3-4405-a951-1f0fe5139a0d] PACKER OUT ==> azure-arm: Get-Service : Cannot find any service with service name 'WindowsAzureTelemetryService'.
[0ca7f19d-2eb3-4405-a951-1f0fe5139a0d] PACKER OUT ==> azure-arm: At C:\DeprovisioningScript.ps1:4 char:9
[0ca7f19d-2eb3-4405-a951-1f0fe5139a0d] PACKER OUT ==> azure-arm: + while ((Get-Service WindowsAzureTelemetryService) -and ((Get-Service  ...
[0ca7f19d-2eb3-4405-a951-1f0fe5139a0d] PACKER OUT ==> azure-arm: +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[0ca7f19d-2eb3-4405-a951-1f0fe5139a0d] PACKER OUT ==> azure-arm:     + CategoryInfo          : ObjectNotFound: (WindowsAzureTelemetryService:String) [Get-Service], ServiceCommandExcep
[0ca7f19d-2eb3-4405-a951-1f0fe5139a0d] PACKER OUT ==> azure-arm:    tion
[0ca7f19d-2eb3-4405-a951-1f0fe5139a0d] PACKER OUT ==> azure-arm:     + FullyQualifiedErrorId : NoServiceFoundForGivenName,Microsoft.PowerShell.Commands.GetServiceCommand
[0ca7f19d-2eb3-4405-a951-1f0fe5139a0d] PACKER OUT ==> azure-arm:
[0ca7f19d-2eb3-4405-a951-1f0fe5139a0d] PACKER OUT     azure-arm: IMAGE_STATE_UNDEPLOYABLE
[0ca7f19d-2eb3-4405-a951-1f0fe5139a0d] PACKER OUT     azure-arm: IMAGE_STATE_UNDEPLOYABLE
[0ca7f19d-2eb3-4405-a951-1f0fe5139a0d] PACKER OUT     azure-arm: IMAGE_STATE_UNDEPLOYABLE
[0ca7f19d-2eb3-4405-a951-1f0fe5139a0d] PACKER OUT     azure-arm: IMAGE_STATE_UNDEPLOYABLE
[0ca7f19d-2eb3-4405-a951-1f0fe5139a0d] PACKER OUT     azure-arm: IMAGE_STATE_UNDEPLOYABLE
[0ca7f19d-2eb3-4405-a951-1f0fe5139a0d] PACKER OUT     azure-arm: IMAGE_STATE_UNDEPLOYABLE
[0ca7f19d-2eb3-4405-a951-1f0fe5139a0d] PACKER OUT     azure-arm: IMAGE_STATE_UNDEPLOYABLE

Relevant info from my template includes:

...
        "vmProfile": {
            "vmSize": "Standard_D2_v5",
            "osDiskSizeGB": 200
        },
        "source": {
            "type": "PlatformImage",
            "publisher": "MicrosoftWindowsServer",
            "offer": "WindowsServer",
            "sku": "2022-Datacenter",
            "version": "latest"
        },
        "customize": [
            {
                "type": "PowerShell",
                "name": "Setup",
                "runElevated": true,
                "scriptUri": "https://myimages.blob.core.windows.net/image-setup-scripts/windows_jumpbox_vmss_setup.ps1"
            },
            {
                "type": "WindowsRestart",
                "restartCheckCommand": "echo Azure-Image-Builder-Restarted-the-VM  > c:\\buildArtifacts\\azureImageBuilderRestart.txt",
                "restartTimeout": "5m"
            },
            {
                "type": "PowerShell",
                "name": "settingUpMgmtAgtPath",
                "runElevated": false,
                "inline": [
                    "mkdir c:\\buildActions",
                    "echo Azure-Image-Builder-Was-Here  > c:\\buildActions\\buildActionsOutput.txt"
                ]
            },
            {
                "type": "WindowsUpdate",
                "searchCriteria": "IsInstalled=0",
                "filters": [
                    "exclude:$_.Title -like '*Preview*'",
                    "include:$true"
                ],
                "updateLimit": 20
            }
        ],

...

Is there anything obvious I'm missing here? I took the customization steps from the Windows Managed Image template, and customized the setup script. My setup script runs without error.

@Peralysis
Copy link

Any updates for this issue? I'm seeing almost the same error suddenly and the suggestions I found here didn't resolve it for me: https://docs.microsoft.com/en-us/azure/virtual-machines/linux/image-builder-troubleshoot#sysprep-timing

My error is slightly different, though. Exception thrown trying to get the WindowsAzureTelemetryService just before attempting to get the WindowsAzureGuestAgent

From my logs:

[1e333e01-b8d7-45d3-9295-1f49870c39e1] PACKER OUT     azure-arm: Write-Output '>>> Waiting for GA Service (RdAgent) to start ...'
[1e333e01-b8d7-45d3-9295-1f49870c39e1] PACKER OUT ==> azure-arm: Get-Service : Cannot find any service with service name 'WindowsAzureTelemetryService'.
[1e333e01-b8d7-45d3-9295-1f49870c39e1] PACKER OUT ==> azure-arm: At C:\DeprovisioningScript.ps1:4 char:9
[1e333e01-b8d7-45d3-9295-1f49870c39e1] PACKER OUT ==> azure-arm: + while ((Get-Service WindowsAzureTelemetryService) -and ((Get-Service  ...
[1e333e01-b8d7-45d3-9295-1f49870c39e1] PACKER OUT     azure-arm: while ((Get-Service RdAgent).Status -ne 'Running') { Start-Sleep -s 5 }
[1e333e01-b8d7-45d3-9295-1f49870c39e1] PACKER OUT ==> azure-arm: +         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[1e333e01-b8d7-45d3-9295-1f49870c39e1] PACKER OUT     azure-arm: Write-Output '>>> Waiting for GA Service (WindowsAzureTelemetryService) to start ...'
[1e333e01-b8d7-45d3-9295-1f49870c39e1] PACKER OUT     azure-arm: while ((Get-Service WindowsAzureTelemetryService) -and ((Get-Service WindowsAzureTelemetryService).Status -ne 'Running')) { Start-Sleep -s 5 }
[1e333e01-b8d7-45d3-9295-1f49870c39e1] PACKER OUT     azure-arm: Write-Output '>>> Waiting for GA Service (WindowsAzureGuestAgent) to start ...'
[1e333e01-b8d7-45d3-9295-1f49870c39e1] PACKER OUT     azure-arm: while ((Get-Service WindowsAzureGuestAgent).Status -ne 'Running') { Start-Sleep -s 5 }
[1e333e01-b8d7-45d3-9295-1f49870c39e1] PACKER OUT     azure-arm: Write-Output '>>> Sysprepping VM ...'
[1e333e01-b8d7-45d3-9295-1f49870c39e1] PACKER ERR ==> azure-arm: Deleting individual resources ...
[1e333e01-b8d7-45d3-9295-1f49870c39e1] PACKER OUT     azure-arm: if( Test-Path $Env:SystemRoot\system32\Sysprep\unattend.xml ) {
[1e333e01-b8d7-45d3-9295-1f49870c39e1] PACKER OUT     azure-arm:   Remove-Item $Env:SystemRoot\system32\Sysprep\unattend.xml -Force
[1e333e01-b8d7-45d3-9295-1f49870c39e1] PACKER OUT     azure-arm: }
[1e333e01-b8d7-45d3-9295-1f49870c39e1] PACKER OUT     azure-arm: & $Env:SystemRoot\System32\Sysprep\Sysprep.exe /oobe /generalize /quiet /quit
[1e333e01-b8d7-45d3-9295-1f49870c39e1] PACKER OUT     azure-arm: while($true) {
[1e333e01-b8d7-45d3-9295-1f49870c39e1] PACKER OUT     azure-arm:   $imageState = (Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\State).ImageState
[1e333e01-b8d7-45d3-9295-1f49870c39e1] PACKER OUT     azure-arm:   Write-Output $imageState
[1e333e01-b8d7-45d3-9295-1f49870c39e1] PACKER OUT     azure-arm:   if ($imageState -eq 'IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE') { break }
[1e333e01-b8d7-45d3-9295-1f49870c39e1] PACKER OUT     azure-arm:   Start-Sleep -s 5
[1e333e01-b8d7-45d3-9295-1f49870c39e1] PACKER OUT     azure-arm: }
[1e333e01-b8d7-45d3-9295-1f49870c39e1] PACKER OUT     azure-arm: Write-Output '>>> Sysprep complete ...'
[1e333e01-b8d7-45d3-9295-1f49870c39e1] PACKER OUT     azure-arm: >>> Waiting for GA Service (RdAgent) to start ...
[1e333e01-b8d7-45d3-9295-1f49870c39e1] PACKER OUT     azure-arm: >>> Waiting for GA Service (WindowsAzureTelemetryService) to start ...
[1e333e01-b8d7-45d3-9295-1f49870c39e1] PACKER OUT ==> azure-arm:     + CategoryInfo          : ObjectNotFound: (WindowsAzureTelemetryService:String) [Get-Service], ServiceCommandExcep
[1e333e01-b8d7-45d3-9295-1f49870c39e1] PACKER OUT ==> azure-arm:    tion
[1e333e01-b8d7-45d3-9295-1f49870c39e1] PACKER OUT ==> azure-arm:     + FullyQualifiedErrorId : NoServiceFoundForGivenName,Microsoft.PowerShell.Commands.GetServiceCommand
[1e333e01-b8d7-45d3-9295-1f49870c39e1] PACKER OUT ==> azure-arm:
[1e333e01-b8d7-45d3-9295-1f49870c39e1] PACKER OUT ==> azure-arm: Provisioning step had errors: Running the cleanup provisioner, if present...

@MichaelRandall-CFS
Copy link

MichaelRandall-CFS commented Jun 26, 2023

I am sure most of these issues are related to Microsoft Defender for Endpoint (MDE). you can see more information here on a related issue with packer.

actions/runner-images#6251

the problem with packer and azure can be solved with a tag

"ExcludeMdeAutoProvisioning": "True"

however, I have no idea if there is work around for image builder. Microsoft can we please have some advice on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants