I have problems running an azure-arm packer build with PowerShell provision scripts. It works with Packer 1.4.0, fails with 1.5.1 and the nightly build 1.5.2-dev.
Steps to reproduce this issue
Run a packer build with azure-arm builder, the first provision script runs in elevated mode. I haven't tried to run a normal provision script yet.
1.5.1 also tried 1.5.2 nightly from GitHub releases
Click to expand!
{
"variables": {
"docker_pkg_version": "19.03.5",
"compose_pkg_version": "1.25.1",
"cygwin_pkg_list": "openssh,vim,git,statgrab,jq,make",
"fips_enabled": "0",
"client_id": "secret",
"client_secret": "secret",
"tenant_id": "secret",
"subscription_id": "secret",
"rg": "",
"name": "",
"offer": "",
"sku": "",
"location": "West US",
"isolation": "process",
"packer_pkg_version": "",
"qemu_img_pkg_version": "",
"inspec_pkg_version": "",
"inspec_profile": "test/jenkins-windows",
"vm_size": "Standard_D4s_v3"
},
"builders": [
{
"type": "azure-arm",
"client_id": "{{ user `client_id` }}",
"client_secret": "{{ user `client_secret` }}",
"tenant_id": "{{ user `tenant_id` }}",
"subscription_id": "{{ user `subscription_id` }}",
"managed_image_name": "{{ isotime \"2006-01-02-1504\" }}-{{ user `name` }}",
"managed_image_resource_group_name": "{{ user `rg` }}",
"managed_image_storage_account_type": "Standard_LRS",
"os_type": "Windows",
"image_publisher": "MicrosoftWindowsServer",
"image_offer": "{{ user `offer` }}",
"image_sku": "{{ user `sku` }}",
"image_version": "{{ user `version` }}",
"communicator": "winrm",
"winrm_use_ssl": "true",
"winrm_insecure": "true",
"winrm_timeout": "30m",
"winrm_username": "packer",
"azure_tags": {
"role": "jenkins-agent",
"agent_type": "{{ user `name` }}",
"project": "TAR-CICD-INFR"
},
"location": "{{ user `location` }}",
"vm_size": "{{ user `vm_size` }}"
}
],
"provisioners": [
{
"elevated_user": "packer",
"elevated_password": "{{.WinRMPassword}}",
"type": "powershell",
"scripts": [
"win/scripts/ver.ps1",
"win/scripts/install-cumulative-update.ps1"
]
},
{
"type": "windows-restart",
"restart_timeout": "45m"
},
{
"type": "powershell",
"scripts": [
"win/scripts/ver.ps1",
"win/scripts/features.ps1",
"win/scripts/tcp-settings.ps1",
"win/scripts/disable-defender.ps1",
"win/scripts/disable-win-updates.ps1"
],
"environment_vars": [
"CHECK_WINDOWS_VERSION=1",
"DOCKER_PKG_VERSION={{ user `docker_pkg_version` }}",
"ISOLATION={{ user `isolation` }}"
]
},
{
"type": "windows-restart"
},
{
"type": "powershell",
"scripts": [
"win/scripts/fips.ps1",
"win/scripts/setup.ps1"
],
"environment_vars": [
"DOCKER_PKG_VERSION={{ user `docker_pkg_version` }}",
"COMPOSE_PKG_VERSION={{ user `compose_pkg_version` }}",
"CYGWIN_PKG_LIST={{ user `cygwin_pkg_list`}}",
"FIPS_ENABLED={{ user `fips_enabled` }}"
],
"only": [
"amazon-ebs"
]
},
{
"type": "powershell",
"scripts": [
"win/scripts/install-docker.ps1",
"win/scripts/install-compose.ps1",
"win/scripts/java.ps1",
"win/scripts/git.ps1",
"win/scripts/make.ps1",
"win/scripts/fips.ps1",
"win/scripts/disable-ssh.ps1"
],
"environment_vars": [
"DOCKER_PKG_VERSION={{ user `docker_pkg_version` }}",
"COMPOSE_PKG_VERSION={{ user `compose_pkg_version` }}",
"FIPS_ENABLED={{ user `fips_enabled` }}"
],
"only": [
"azure-arm"
]
},
{
"type": "inspec",
"profile": "{{ user `inspec_profile` }}",
"extra_arguments": [
"--no-distinct-exit"
],
"inspec_env_vars": [
"FIPS_ENABLED={{ user `fips_enabled` }}",
"DOCKER_PKG_VERSION={{ user `docker_pkg_version` }}",
"COMPOSE_PKG_VERSION={{ user `compose_pkg_version` }}",
"PACKER_PKG_VERSION={{ user `packer_pkg_version` }}",
"QEMU_IMG_PKG_VERSION={{ user `qemu_img_pkg_version` }}",
"INSPEC_PKG_VERSION={{ user `inspec_pkg_version` }}"
]
},
{
"type": "powershell",
"scripts": [
"win/scripts/sysprep-azure.ps1"
]
}
],
"post-processors": [
{
"type": "manifest"
}
]
}
My first provision script win/scripts/ver.ps1
looks like this:
Click to expand!
$ProgressPreference = 'SilentlyContinue'
$ErrorActionPreference = 'Stop'
# fetch the current version number from host
$current=(Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion")
$currUBR=$current.UBR
$prefix="$($current.CurrentMajorVersionNumber).$($current.CurrentMinorVersionNumber).$($current.CurrentBuildNumber)."
Write-Output "The host OS is $($current.ProductName) $($current.InstallationType) $($current.ReleaseId), build $prefix$currUBR."
if ($env:CHECK_WINDOWS_VERSION) {
Write-Output "Checking if host OS is up to date..."
# fetch the tags from MCR, filter them with host version prefix, sort the update revisions and pick the highest
$json=$(Invoke-WebRequest -UseBasicParsing https://mcr.microsoft.com/v2/windows/servercore/tags/list | ConvertFrom-Json)
$hubUBR=($json.tags | Where-Object -FilterScript { $_.StartsWith($prefix) -and $_ -Match "^\d+\.\d+\.\d+\.\d+$" } |%{[System.Version]$_}|sort)[-1].Revision
Write-Output "The host OS version is $prefix$currUBR, latest Windows Docker base image OS version is $prefix$hubUBR."
if ($currUBR -lt $hubUBR) {
Write-Error "Your host has update revision $currUBR, but should be updated to $hubUBR!"
} else {
Write-Output "The host is up to date."
}
}
packer running from Ubuntu 18.04 amd64
09:59:40 ==> azure-arm: -> IP Address : '104.45.228.5'
09:59:40 2020/01/17 08:59:30 packer_linux_amd64 plugin: Error asking for input: no available tty
09:59:40 2020/01/17 08:59:30 packer_linux_amd64 plugin: Waiting for WinRM, up to timeout: 30m0s
09:59:40 ==> azure-arm: Waiting for WinRM to become available...
09:59:40 2020/01/17 08:59:30 packer_linux_amd64 plugin: [INFO] Attempting WinRM connection...
09:59:40 2020/01/17 08:59:30 packer_linux_amd64 plugin: [DEBUG] connecting to remote shell using WinRM
09:59:40 2020/01/17 08:59:37 packer_linux_amd64 plugin: Checking that WinRM is connected with: 'powershell.exe -EncodedCommand aQBmACAAKABUAGUAcwB0AC0AUABhAHQAaAAgAHYAYQByAGkAYQBiAGwAZQA6AGcAbABvAGIAYQBsADoAUAByAG8AZwByAGUAcwBzAFAAcgBlAGYAZQByAGUAbgBjAGUAKQB7ACQAUAByAG8AZwByAGUAcwBzAFAAcgBlAGYAZQByAGUAbgBjAGUAPQAnAFMAaQBsAGUAbgB0AGwAeQBDAG8AbgB0AGkAbgB1AGUAJwB9ADsAIABlAGMAaABvACAAIgBXAGkAbgBSAE0AIABjAG8AbgBuAGUAYwB0AGUAZAAuACIA'
09:59:40 2020/01/17 08:59:38 packer_linux_amd64 plugin: [INFO] starting remote command: powershell.exe -EncodedCommand aQBmACAAKABUAGUAcwB0AC0AUABhAHQAaAAgAHYAYQByAGkAYQBiAGwAZQA6AGcAbABvAGIAYQBsADoAUAByAG8AZwByAGUAcwBzAFAAcgBlAGYAZQByAGUAbgBjAGUAKQB7ACQAUAByAG8AZwByAGUAcwBzAFAAcgBlAGYAZQByAGUAbgBjAGUAPQAnAFMAaQBsAGUAbgB0AGwAeQBDAG8AbgB0AGkAbgB1AGUAJwB9ADsAIABlAGMAaABvACAAIgBXAGkAbgBSAE0AIABjAG8AbgBuAGUAYwB0AGUAZAAuACIA
09:59:46 ==> azure-arm: #< CLIXML
09:59:46 azure-arm: WinRM connected.
09:59:46 2020/01/17 08:59:46 packer_linux_amd64 plugin: [INFO] command 'powershell.exe -EncodedCommand aQBmACAAKABUAGUAcwB0AC0AUABhAHQAaAAgAHYAYQByAGkAYQBiAGwAZQA6AGcAbABvAGIAYQBsADoAUAByAG8AZwByAGUAcwBzAFAAcgBlAGYAZQByAGUAbgBjAGUAKQB7ACQAUAByAG8AZwByAGUAcwBzAFAAcgBlAGYAZQByAGUAbgBjAGUAPQAnAFMAaQBsAGUAbgB0AGwAeQBDAG8AbgB0AGkAbgB1AGUAJwB9ADsAIABlAGMAaABvACAAIgBXAGkAbgBSAE0AIABjAG8AbgBuAGUAYwB0AGUAZAAuACIA' exited with code: 0
09:59:46 ==> azure-arm: <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>
09:59:46 2020/01/17 08:59:46 packer_linux_amd64 plugin: Connected to machine
09:59:46 ==> azure-arm: Connected to WinRM!
09:59:46 2020/01/17 08:59:46 packer_linux_amd64 plugin: Error asking for input: no available tty
09:59:46 2020/01/17 08:59:46 packer_linux_amd64 plugin: Running the provision hook
09:59:46 2020/01/17 08:59:46 [INFO] (telemetry) Starting provisioner powershell
09:59:46 2020/01/17 08:59:46 Error asking for input: no available tty
09:59:46 ==> azure-arm: Provisioning with Powershell...
09:59:46 ==> azure-arm: Provisioning with powershell script: win/scripts/ver.ps1
09:59:46 2020/01/17 08:59:46 packer_linux_amd64 plugin: Opening win/scripts/ver.ps1 for reading
09:59:46 2020/01/17 08:59:46 packer_linux_amd64 plugin: Uploading env vars to c:/Windows/Temp/packer-ps-env-vars-5e21763d-cc44-cea6-0826-e7a6b3e94bd6.ps1
09:59:46 2020/01/17 08:59:46 packer_linux_amd64 plugin: [INFO] 74 bytes written for 'uploadData'
09:59:46 2020/01/17 08:59:46 [INFO] 74 bytes written for 'uploadData'
09:59:46 2020/01/17 08:59:46 packer_linux_amd64 plugin: Uploading file to 'c:/Windows/Temp/packer-ps-env-vars-5e21763d-cc44-cea6-0826-e7a6b3e94bd6.ps1'
09:59:48 2020/01/17 08:59:48 packer_linux_amd64 plugin: #< CLIXML
09:59:49 2020/01/17 08:59:49 packer_linux_amd64 plugin: <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
09:59:49 2020/01/17 08:59:49 packer_linux_amd64 plugin: 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-5e21763d-cc44-cea6-0826-e7a6b3e94bd6.ps1; &'c:/Windows/Temp/script-5e21763d-9b3a-2948-6d3f-6f3d344d868b.ps1'; exit $LastExitCode }"
09:59:49 2020/01/17 08:59:49 packer_linux_amd64 plugin: 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-5e21763d-cc44-cea6-0826-e7a6b3e94bd6.ps1; &'c:/Windows/Temp/script-5e21763d-9b3a-2948-6d3f-6f3d344d868b.ps1'; exit $LastExitCode }" > %SYSTEMROOT%/Temp/packer-5e217785-fb7f-a442-88d8-86520c890a36.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-5e21763d-cc44-cea6-0826-e7a6b3e94bd6.ps1; &'c:/Windows/Temp/script-5e21763d-9b3a-2948-6d3f-6f3d344d868b.ps1'; exit $LastExitCode }" > %SYSTEMROOT%/Temp/packer-5e217785-fb7f-a442-88d8-86520c890a36.out 2>&1] for use in XML string
09:59:49 2020/01/17 08:59:49 packer_linux_amd64 plugin: 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-5e21763d-cc44-cea6-0826-e7a6b3e94bd6.ps1; &'c:/Windows/Temp/script-5e21763d-9b3a-2948-6d3f-6f3d344d868b.ps1'; exit $LastExitCode }" > %SYSTEMROOT%/Temp/packer-5e217785-fb7f-a442-88d8-86520c890a36.out 2>&1] to [C:/Windows/Temp/packer-elevated-shell-5e217785-d4d4-7c72-d85a-0e6089798e8d.ps1]
09:59:49 2020/01/17 08:59:49 packer_linux_amd64 plugin: [INFO] 3198 bytes written for 'uploadData'
09:59:49 2020/01/17 08:59:49 [INFO] 3198 bytes written for 'uploadData'
09:59:49 2020/01/17 08:59:49 packer_linux_amd64 plugin: <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>Uploading file to 'C:/Windows/Temp/packer-elevated-shell-5e217785-d4d4-7c72-d85a-0e6089798e8d.ps1'
09:59:56 2020/01/17 08:59:55 packer_linux_amd64 plugin: #< CLIXML
09:59:56 2020/01/17 08:59:56 packer_linux_amd64 plugin: <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
09:59:56 2020/01/17 08:59:56 packer_linux_amd64 plugin: [INFO] 1281 bytes written for 'uploadData'
09:59:56 2020/01/17 08:59:56 [INFO] 1281 bytes written for 'uploadData'
09:59:56 2020/01/17 08:59:56 packer_linux_amd64 plugin: <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>Uploading file to 'c:/Windows/Temp/script-5e21763d-9b3a-2948-6d3f-6f3d344d868b.ps1'
09:59:59 2020/01/17 08:59:59 packer_linux_amd64 plugin: #< CLIXML
10:00:00 2020/01/17 09:00:00 packer_linux_amd64 plugin: <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
10:00:00 2020/01/17 09:00:00 packer_linux_amd64 plugin: <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>[INFO] starting remote command: powershell -executionpolicy bypass -file "C:/Windows/Temp/packer-elevated-shell-5e217785-d4d4-7c72-d85a-0e6089798e8d.ps1"
10:00:03 ==> azure-arm: (39,4):Task:
10:00:03 ==> azure-arm: At C:\Windows\Temp\packer-elevated-shell-5e217785-d4d4-7c72-d85a-0e6089798e8d.ps1:60 char:1
10:00:03 ==> azure-arm: + $f.RegisterTaskDefinition($name, $t, 6, "packer", $password, $logon_t ...
10:00:03 ==> azure-arm: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10:00:03 ==> azure-arm: + CategoryInfo : OperationStopped: (:) [], COMException
10:00:03 ==> azure-arm: + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
10:00:03 ==> azure-arm:
10:00:03 ==> azure-arm: The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
10:00:03 ==> azure-arm: At C:\Windows\Temp\packer-elevated-shell-5e217785-d4d4-7c72-d85a-0e6089798e8d.ps1:61 char:1
10:00:03 ==> azure-arm: + $t = $f.GetTask("\$name")
10:00:03 ==> azure-arm: + ~~~~~~~~~~~~~~~~~~~~~~~~~
10:00:03 ==> azure-arm: + CategoryInfo : OperationStopped: (:) [], FileNotFoundException
10:00:03 ==> azure-arm: + FullyQualifiedErrorId : System.IO.FileNotFoundException
10:00:03 ==> azure-arm:
10:00:03 ==> azure-arm: Method invocation failed because [System.__ComObject] does not contain a method named 'Run'.
10:00:03 ==> azure-arm: At C:\Windows\Temp\packer-elevated-shell-5e217785-d4d4-7c72-d85a-0e6089798e8d.ps1:62 char:1
10:00:03 ==> azure-arm: + $t.Run($null) | Out-Null
10:00:03 ==> azure-arm: + ~~~~~~~~~~~~~~~~~~~~~~~~
10:00:03 ==> azure-arm: + CategoryInfo : InvalidOperation: (Run:String) [], RuntimeException
10:00:03 ==> azure-arm: + FullyQualifiedErrorId : MethodNotFound
10:00:03 ==> azure-arm:
I've tried it with Packer 1.4.5, and this worked. Here is the log output.
Click to expand!
14:10:19 ==> azure-arm: Waiting for WinRM to become available...
14:10:19 2020/01/17 13:10:12 packer: 2020/01/17 13:10:12 [INFO] Attempting WinRM connection...
14:10:19 2020/01/17 13:10:12 packer: 2020/01/17 13:10:12 [DEBUG] connecting to remote shell using WinRM
14:10:19 2020/01/17 13:10:19 packer: 2020/01/17 13:10:19 Checking that WinRM is connected with: 'powershell.exe -EncodedCommand aQBmACAAKABUAGUAcwB0AC0AUABhAHQAaAAgAHYAYQByAGkAYQBiAGwAZQA6AGcAbABvAGIAYQBsADoAUAByAG8AZwByAGUAcwBzAFAAcgBlAGYAZQByAGUAbgBjAGUAKQB7ACQAUAByAG8AZwByAGUAcwBzAFAAcgBlAGYAZQByAGUAbgBjAGUAPQAnAFMAaQBsAGUAbgB0AGwAeQBDAG8AbgB0AGkAbgB1AGUAJwB9ADsAIABlAGMAaABvACAAIgBXAGkAbgBSAE0AIABjAG8AbgBuAGUAYwB0AGUAZAAuACIA'
14:10:20 2020/01/17 13:10:19 packer: 2020/01/17 13:10:19 [INFO] starting remote command: powershell.exe -EncodedCommand aQBmACAAKABUAGUAcwB0AC0AUABhAHQAaAAgAHYAYQByAGkAYQBiAGwAZQA6AGcAbABvAGIAYQBsADoAUAByAG8AZwByAGUAcwBzAFAAcgBlAGYAZQByAGUAbgBjAGUAKQB7ACQAUAByAG8AZwByAGUAcwBzAFAAcgBlAGYAZQByAGUAbgBjAGUAPQAnAFMAaQBsAGUAbgB0AGwAeQBDAG8AbgB0AGkAbgB1AGUAJwB9ADsAIABlAGMAaABvACAAIgBXAGkAbgBSAE0AIABjAG8AbgBuAGUAYwB0AGUAZAAuACIA
14:10:28 ==> azure-arm: #< CLIXML
14:10:28 azure-arm: WinRM connected.
14:10:28 2020/01/17 13:10:28 packer: 2020/01/17 13:10:28 [INFO] command 'powershell.exe -EncodedCommand aQBmACAAKABUAGUAcwB0AC0AUABhAHQAaAAgAHYAYQByAGkAYQBiAGwAZQA6AGcAbABvAGIAYQBsADoAUAByAG8AZwByAGUAcwBzAFAAcgBlAGYAZQByAGUAbgBjAGUAKQB7ACQAUAByAG8AZwByAGUAcwBzAFAAcgBlAGYAZQByAGUAbgBjAGUAPQAnAFMAaQBsAGUAbgB0AGwAeQBDAG8AbgB0AGkAbgB1AGUAJwB9ADsAIABlAGMAaABvACAAIgBXAGkAbgBSAE0AIABjAG8AbgBuAGUAYwB0AGUAZAAuACIA' exited with code: 0
14:10:28 ==> azure-arm: <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>
14:10:28 ==> azure-arm: Connected to WinRM!
14:10:28 2020/01/17 13:10:28 packer: 2020/01/17 13:10:28 Connected to machine
14:10:28 2020/01/17 13:10:28 packer: 2020/01/17 13:10:28 Error asking for input: no available tty
14:10:28 2020/01/17 13:10:28 packer: 2020/01/17 13:10:28 Running the provision hook
14:10:28 2020/01/17 13:10:28 [INFO] (telemetry) Starting provisioner powershell
14:10:28 2020/01/17 13:10:28 Error asking for input: no available tty
14:10:28 ==> azure-arm: Provisioning with Powershell...
14:10:28 ==> azure-arm: Provisioning with powershell script: win/scripts/ver.ps1
14:10:28 2020/01/17 13:10:28 packer: 2020/01/17 13:10:28 Opening win/scripts/ver.ps1 for reading
14:10:28 2020/01/17 13:10:28 packer: 2020/01/17 13:10:28 Uploading env vars to c:/Windows/Temp/packer-ps-env-vars-5e21b0c3-6305-227f-6f90-c0f31900a51a.ps1
14:10:28 2020/01/17 13:10:28 packer: 2020/01/17 13:10:28 [INFO] 74 bytes written for 'uploadData'
14:10:28 2020/01/17 13:10:28 [INFO] 74 bytes written for 'uploadData'
14:10:28 2020/01/17 13:10:28 packer: 2020/01/17 13:10:28 Uploading file to 'c:/Windows/Temp/packer-ps-env-vars-5e21b0c3-6305-227f-6f90-c0f31900a51a.ps1'
14:10:30 2020/01/17 13:10:30 packer: #< CLIXML
14:10:31 2020/01/17 13:10:31 packer: <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
14:10:31 2020/01/17 13:10:31 packer: 2020/01/17 13:10:31 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-5e21b0c3-6305-227f-6f90-c0f31900a51a.ps1; &'c:/Windows/Temp/script-5e21b0c3-f1f7-faa4-fcf3-40bf0946bd51.ps1'; exit $LastExitCode }"
14:10:31 2020/01/17 13:10:31 packer: 2020/01/17 13:10:31 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-5e21b0c3-6305-227f-6f90-c0f31900a51a.ps1; &'c:/Windows/Temp/script-5e21b0c3-f1f7-faa4-fcf3-40bf0946bd51.ps1'; exit $LastExitCode }" > %SYSTEMROOT%/Temp/packer-5e21b247-1a33-9bab-33bb-fa96e00b3404.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-5e21b0c3-6305-227f-6f90-c0f31900a51a.ps1; &'c:/Windows/Temp/script-5e21b0c3-f1f7-faa4-fcf3-40bf0946bd51.ps1'; exit $LastExitCode }" > %SYSTEMROOT%/Temp/packer-5e21b247-1a33-9bab-33bb-fa96e00b3404.out 2>&1] for use in XML string
14:10:31 2020/01/17 13:10:31 packer: 2020/01/17 13:10:31 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-5e21b0c3-6305-227f-6f90-c0f31900a51a.ps1; &'c:/Windows/Temp/script-5e21b0c3-f1f7-faa4-fcf3-40bf0946bd51.ps1'; exit $LastExitCode }" > %SYSTEMROOT%/Temp/packer-5e21b247-1a33-9bab-33bb-fa96e00b3404.out 2>&1] to [C:/Windows/Temp/packer-elevated-shell-5e21b247-26af-84e0-4859-a486ccd7e854.ps1]
14:10:31 2020/01/17 13:10:31 packer: 2020/01/17 13:10:31 [INFO] 3230 bytes written for 'uploadData'
14:10:31 2020/01/17 13:10:31 [INFO] 3230 bytes written for 'uploadData'
14:10:31 2020/01/17 13:10:31 packer: <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>2020/01/17 13:10:31 Uploading file to 'C:/Windows/Temp/packer-elevated-shell-5e21b247-26af-84e0-4859-a486ccd7e854.ps1'
14:10:34 2020/01/17 13:10:34 packer: #< CLIXML
14:10:35 2020/01/17 13:10:35 packer: <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
14:10:35 2020/01/17 13:10:35 packer: 2020/01/17 13:10:35 [INFO] 1281 bytes written for 'uploadData'
14:10:35 2020/01/17 13:10:35 [INFO] 1281 bytes written for 'uploadData'
14:10:35 2020/01/17 13:10:35 packer: <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>2020/01/17 13:10:35 Uploading file to 'c:/Windows/Temp/script-5e21b0c3-f1f7-faa4-fcf3-40bf0946bd51.ps1'
14:10:38 2020/01/17 13:10:37 packer: #< CLIXML
14:10:39 2020/01/17 13:10:39 packer: <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
14:10:40 2020/01/17 13:10:39 packer: <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>2020/01/17 13:10:39 [INFO] starting remote command: powershell -executionpolicy bypass -file "C:/Windows/Temp/packer-elevated-shell-5e21b247-26af-84e0-4859-a486ccd7e854.ps1"
14:10:42 2020/01/17 13:10:41 packer: 2020/01/17 13:10:41 [INFO] command 'powershell -executionpolicy bypass -file "C:/Windows/Temp/packer-elevated-shell-5e21b247-26af-84e0-4859-a486ccd7e854.ps1"' exited with code: 0
14:10:42 2020/01/17 13:10:41 packer: 2020/01/17 13:10:41 [INFO] RPC endpoint: Communicator ended with: 0
14:10:42 2020/01/17 13:10:41 [INFO] 82 bytes written for 'stdout'
14:10:42 2020/01/17 13:10:41 [INFO] 0 bytes written for 'stderr'
14:10:42 2020/01/17 13:10:41 [INFO] RPC client: Communicator ended with: 0
14:10:42 2020/01/17 13:10:41 [INFO] RPC endpoint: Communicator ended with: 0
14:10:42 azure-arm: The host OS is Windows Server Datacenter Server Core 1809, build 10.0.17763.973.
14:10:42 2020/01/17 13:10:41 packer: 2020/01/17 13:10:41 [INFO] 82 bytes written for 'stdout'
14:10:42 2020/01/17 13:10:41 packer: 2020/01/17 13:10:41 [INFO] 0 bytes written for 'stderr'
14:10:42 2020/01/17 13:10:41 packer: 2020/01/17 13:10:41 [INFO] RPC client: Communicator ended with: 0
14:10:42 2020/01/17 13:10:41 packer: 2020/01/17 13:10:41 c:/Windows/Temp/script-5e21b0c3-f1f7-faa4-fcf3-40bf0946bd51.ps1 returned with exit code 0
Thanks, I'll take a look for the next release.
Hi @StefanScherer thanks for reporting this issue. I confirmed I can reproduce the issue when using a simplified powershell provisioner config using the .WinRMPasswd variable.
{
"type": "powershell",
"elevated_user": "packer",
"elevated_password": "{{.WinRMPassword}}",
"inline": ["Write-Host \"HELLO NEW USER; random text\""]
}
Changing the the elelvated information so that the PowerShell script is run as a service account throws no error
{
"type": "powershell",
"elevated_user": "SYSTEM",
"elevated_password": "",
"inline": ["Write-Host \"HELLO NEW USER; random text\""]
}
There was a change to how the WinRMPasswd information is interpolated so I need to look a little deeper there and report back.
Hello @StefanScherer! This should be fixed by #8670 . In looking into the issue further it appears that {{ .WinRMPassword}}
was elevating to an empty string causing the elevation script execution to fail. The PR changes the builder a bit to ensure that WinRMPassword
always has a valid value. โจThere are some test binaries available via the link below if you would like to test the fix.
https://circleci.com/gh/hashicorp/packer/31314#artifacts/containers/0
Thanks!
Hello @nywilken Thanks for the fix and also the link to the artifacts. I'll give it a try with my packer template.
@nywilken Thanks again for the fix. I can report back that this fixes my problem with the azure-arm builds. ๐
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.
Most helpful comment
Hello @StefanScherer! This should be fixed by #8670 . In looking into the issue further it appears that
{{ .WinRMPassword}}
was elevating to an empty string causing the elevation script execution to fail. The PR changes the builder a bit to ensure thatWinRMPassword
always has a valid value. โจThere are some test binaries available via the link below if you would like to test the fix.https://circleci.com/gh/hashicorp/packer/31314#artifacts/containers/0
Thanks!