Hello All,
I am stuck with simple Packer template which provisions Windows 10 image in
Azure. Template includes inline PowerShell script which is executed with
elevated privileges and installs Azure PowerShell modules and then
generalizes image using sysprep. The issue is that Packer simply hangs
during running the inline script. I’ve tried to debug this script on the
separate VM and it works as expected, but when it is executed within Packer
template it hangs for some reason. Template and debug logs are provided
below:
Any ideas what am I doing wrong or this is a bug?
{
"variables": {
"azure_region": "West Europe",
"azure_image_publisher": "MicrosoftWindowsDesktop",
"azure_image_offer": "Windows-10",
"azure_image_sku": "rs5-pron",
"azure_resource_group": "Test-RG",
"azure_vm_size": "Standard_D2s_v3"
},
"builders": [{
"type": "azure-arm",
"client_id": "{{user `azure_client_id`}}",
"client_secret": "{{user `azure_client_secret`}}",
"tenant_id": "{{user `azure_tenant_id`}}",
"subscription_id": "{{user `azure_subscription_id`}}",
"managed_image_resource_group_name": "{{user
`azure_resource_group`}}",
"managed_image_name": "{{user `azure_image_offer` | lower}}-{{user
`azure_image_sku` | lower}}-{{isotime \"02Jan2006_1504\"}}",
"os_type": "Windows",
"image_publisher": "{{user `azure_image_publisher`}}",
"image_offer": "{{user `azure_image_offer`}}",
"image_sku": "{{user `azure_image_sku`}}",
"communicator": "winrm",
"winrm_use_ssl": true,
"winrm_insecure": true,
"winrm_timeout": "5m",
"winrm_username": "packer",
"location": "{{user `azure_region`}}",
"vm_size": "{{user `azure_vm_size`}}"
}],
"provisioners": [{
"type": "powershell",
"elevated_user": "packer",
"elevated_password": "{{.WinRMPassword}}",
"inline": [
"Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope
LocalMachine -Force",
"Install-PackageProvider -Name Nuget -MinimumVersion 2.8.5.201
-Force",
"Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted",
"Install-Module -Name Az",
"Import-Module Az",
"& $env:SystemRoot\\System32\\Sysprep\\Sysprep.exe /oobe
/generalize /quiet /quit",
"while($true) { $imageState = Get-ItemProperty
HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup\\State | Select
ImageState; if($imageState.ImageState -ne
'IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE') { Write-Output
$imageState.ImageState; Start-Sleep -s 10 } else { break } }"
]
}]
}
Debug log:
==> azure-arm: Provisioning with Powershell...
2019/06/10 13:04:14 packer.exe: 2019/06/10 13:04:14 Found command:
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope LocalMachine -Force
2019/06/10 13:04:14 packer.exe: 2019/06/10 13:04:14 Found command:
Install-PackageProvider -Name Nuget -MinimumVersion 2.8.5.201 -Force
2019/06/10 13:04:14 packer.exe: 2019/06/10 13:04:14 Found command:
Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted
2019/06/10 13:04:14 packer.exe: 2019/06/10 13:04:14 Found command:
Install-Module -Name Az
2019/06/10 13:04:14 packer.exe: 2019/06/10 13:04:14 Found command:
Import-Module Az
==> azure-arm: Provisioning with powershell script:
C:\Users\easkerov\AppData\Local\Temp\powershell-provisioner337119215
2019/06/10 13:04:14 packer.exe: 2019/06/10 13:04:14 Found command: &
$env:SystemRoot\System32\Sysprep\Sysprep.exe /oobe /generalize /quiet /quit
2019/06/10 13:04:14 packer.exe: 2019/06/10 13:04:14 Found command:
while($true) { $imageState = Get-ItemProperty
HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\State | Select
ImageState; if($imageState.ImageState -ne
'IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE') { Write-Output
$imageState.ImageState; Start-Sleep -s 10 } else { break } }
2019/06/10 13:04:14 packer.exe: 2019/06/10 13:04:14 Opening
C:\Users\easkerov\AppData\Local\Temp\powershell-provisioner337119215 for
reading
2019/06/10 13:04:14 packer.exe: 2019/06/10 13:04:14 Uploading env vars to
c:/Windows/Temp/packer-ps-env-vars-5cfe3672-7c28-9aa9-7377-69c61ab76e2f.ps1
2019/06/10 13:04:14 packer.exe: 2019/06/10 13:04:14 [INFO] 74 bytes written
for 'uploadData'
2019/06/10 13:04:14 [INFO] 74 bytes written for 'uploadData'
2019/06/10 13:04:14 packer.exe: 2019/06/10 13:04:14 Uploading file to
'c:/Windows/Temp/packer-ps-env-vars-5cfe3672-7c28-9aa9-7377-69c61ab76e2f.ps1'
2019/06/10 13:04:15 packer.exe: #< CLIXML
2019/06/10 13:04:16 packer.exe: <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
2019/06/10 13:04:16 packer.exe: 2019/06/10 13:04:16 Building elevated
command wrapper for: powershell -executionpolicy bypass "& { if (Test-Path
variable:global:ProgressPreference){set-variable -name
variable:global:ProgressPreference -value 'SilentlyContinue'};.
c:/Windows/Temp/packer-ps-env-vars-5cfe3672-7c28-9aa9-7377-69c61ab76e2f.ps1;
&'c:/Windows/Temp/script-5cfe3672-4f87-5b9e-285e-e0dcc8d92df4.ps1'; exit
$LastExitCode }"
2019/06/10 13:04:16 packer.exe: 2019/06/10 13:04:16 Command [powershell
-executionpolicy bypass "& { if (Test-Path
variable:global:ProgressPreference){set-variable -name
variable:global:ProgressPreference -value 'SilentlyContinue'};.
c:/Windows/Temp/packer-ps-env-vars-5cfe3672-7c28-9aa9-7377-69c61ab76e2f.ps1;
&'c:/Windows/Temp/script-5cfe3672-4f87-5b9e-285e-e0dcc8d92df4.ps1'; exit
$LastExitCode }" >
%SYSTEMROOT%/Temp/packer-5cfe3930-81a9-eac0-692e-aa06bc696b22.out 2>&1]
converted to [powershell -executionpolicy bypass "& { if (Test-Path
variable:global:ProgressPreference){set-variable -name
variable:global:ProgressPreference -value 'SilentlyContinue'};.
c:/Windows/Temp/packer-ps-env-vars-5cfe3672-7c28-9aa9-7377-69c61ab76e2f.ps1;
&'c:/Windows/Temp/script-5cfe3672-4f87-5b9e-285e-e0dcc8d92df4.ps1';
exit $LastExitCode }" >
%SYSTEMROOT%/Temp/packer-5cfe3930-81a9-eac0-692e-aa06bc696b22.out
2>&1] for use in XML string
2019/06/10 13:04:16 packer.exe: 2019/06/10 13:04:16 Uploading elevated
shell wrapper for command [powershell -executionpolicy bypass "& { if
(Test-Path variable:global:ProgressPreference){set-variable -name
variable:global:ProgressPreference -value 'SilentlyContinue'};.
c:/Windows/Temp/packer-ps-env-vars-5cfe3672-7c28-9aa9-7377-69c61ab76e2f.ps1;
&'c:/Windows/Temp/script-5cfe3672-4f87-5b9e-285e-e0dcc8d92df4.ps1'; exit
$LastExitCode }" >
%SYSTEMROOT%/Temp/packer-5cfe3930-81a9-eac0-692e-aa06bc696b22.out 2>&1] to
[C:/Windows/Temp/packer-elevated-shell-5cfe3930-983a-f36e-80b0-4053f8326643.ps1]
2019/06/10 13:04:16 packer.exe: 2019/06/10 13:04:16 [INFO] 3230 bytes
written for 'uploadData'
2019/06/10 13:04:16 packer.exe: <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>2019/06/10 13:04:16 Uploading file to
'C:/Windows/Temp/packer-elevated-shell-5cfe3930-983a-f36e-80b0-4053f8326643.ps1'
2019/06/10 13:04:16 [INFO] 3230 bytes written for 'uploadData'
2019/06/10 13:04:18 packer.exe: #< CLIXML
2019/06/10 13:04:19 packer.exe: <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
2019/06/10 13:04:19 packer.exe: 2019/06/10 13:04:19 [INFO] 603 bytes
written for 'uploadData'
2019/06/10 13:04:19 packer.exe: <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>2019/06/10 13:04:19 Uploading file to
'c:/Windows/Temp/script-5cfe3672-4f87-5b9e-285e-e0dcc8d92df4.ps1'
2019/06/10 13:04:19 [INFO] 603 bytes written for 'uploadData'
2019/06/10 13:04:20 packer.exe: #< CLIXML
2019/06/10 13:04:21 packer.exe: <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
2019/06/10 13:04:21 packer.exe: <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>2019/06/10 13:04:21 [INFO] starting remote
command: powershell -executionpolicy bypass -file
"C:/Windows/Temp/packer-elevated-shell-5cfe3930-983a-f36e-80b0-4053f8326643.ps1"
--
This mailing list is governed under the HashiCorp Community Guidelines -
https://www.hashicorp.com/community-guidelines.html. Behavior in violation of
those guidelines may result in your removal from this mailing list.
GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to the Google Groups
"Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/packer-tool/534a1552-bdc8-4435-9717-8d3aafcf027c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.