-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Powershell provisioner and #requires directive #9161
Description
Overview of the Issue
Provisioning with powershell provisioner succeeds despite the script being invoked violating a #Requires -Version directive.
Reproduction Steps
Configure a powershell provisioner invoking a script with a #Requires -Version x directive that fails on the to be provisoned target system. Pick a large version number for it to definitely fail on any system. This probably can be reproduced with any requires directive that gets violated during script invocation.
Packer log snippet
2020/05/02 08:13:32 ui: 2020-05-02T08:13:32+02:00: ==> vbox-base-win2012-r2: Provisioning with Powershell...
2020/05/02 08:13:32 ui: 2020-05-02T08:13:32+02:00: ==> vbox-base-win2012-r2: Provisioning with powershell script: scripts/init_provisioning/post-bootstrap.ps1
2020/05/02 08:13:32 packer.exe plugin: Opening scripts/init_provisioning/post-bootstrap.ps1 for reading
2020/05/02 08:13:32 packer.exe plugin: Uploading env vars to c:/Windows/Temp/packer-ps-env-vars-5ead0cbd-97e7-8f63-237a-c34ba075b0e4.ps1
2020/05/02 08:13:32 packer.exe plugin: [INFO] 122 bytes written for 'uploadData'
2020/05/02 08:13:32 packer.exe plugin: Uploading file to 'c:/Windows/Temp/packer-ps-env-vars-5ead0cbd-97e7-8f63-237a-c34ba075b0e4.ps1'
2020/05/02 08:13:32 [INFO] 122 bytes written for 'uploadData'
2020/05/02 08:13:32 packer.exe plugin: Copying file to $env:TEMP\winrmcp-b300f02f-f55c-4e43-6b82-9cb96bb7b655.tmp
2020/05/02 08:13:32 packer.exe plugin: Moving file from $env:TEMP\winrmcp-b300f02f-f55c-4e43-6b82-9cb96bb7b655.tmp to c:\Windows\Temp\packer-ps-env-vars-5ead0cbd-97e7-8f63-237a-c34ba075b0e4.ps1
2020/05/02 08:13:41 packer.exe plugin: Removing temporary file $env:TEMP\winrmcp-b300f02f-f55c-4e43-6b82-9cb96bb7b655.tmp
2020/05/02 08:13:49 packer.exe plugin: [INFO] 1935 bytes written for 'uploadData'
2020/05/02 08:13:49 [INFO] 1935 bytes written for 'uploadData'
2020/05/02 08:13:49 packer.exe plugin: Uploading file to 'C:/Windows/Temp/scripts/post-bootstrap.ps1'
2020/05/02 08:13:49 packer.exe plugin: Copying file to $env:TEMP\winrmcp-9c45e645-e134-4e9d-69d5-0747674cdd84.tmp
2020/05/02 08:13:49 packer.exe plugin: Moving file from $env:TEMP\winrmcp-9c45e645-e134-4e9d-69d5-0747674cdd84.tmp to C:\Windows\Temp\scripts\post-bootstrap.ps1
2020/05/02 08:13:57 packer.exe plugin: Removing temporary file $env:TEMP\winrmcp-9c45e645-e134-4e9d-69d5-0747674cdd84.tmp
2020/05/02 08:14:05 packer.exe plugin: [INFO] starting remote 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-5ead0cbd-97e7-8f63-237a-c34ba075b0e4.ps1; &'C:/Windows/Temp/scripts/post-bootstrap.ps1'; exit $LastExitCode }"
2020/05/02 08:14:15 packer.exe plugin: [INFO] 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-5ead0cbd-97e7-8f63-237a-c34ba075b0e4.ps1; &'C:/Windows/Temp/scripts/post-bootstrap.ps1'; exit $LastExitCode }"' exited with code: 0
2020/05/02 08:14:15 packer.exe plugin: [INFO] RPC endpoint: Communicator ended with: 0
2020/05/02 08:14:15 ui error: 2020-05-02T08:14:15+02:00: ==> vbox-base-win2012-r2: & : Das Skript "post-bootstrap.ps1" kann nicht ausgeführt werden, da es eine
2020/05/02 08:14:15 ui error: 2020-05-02T08:14:15+02:00: ==> vbox-base-win2012-r2: #requires-Anweisung für Windows PowerShell 5.0 enthält. Die für das Skript
2020/05/02 08:14:15 ui error: 2020-05-02T08:14:15+02:00: ==> vbox-base-win2012-r2: erforderliche Version von Windows PowerShell stimmt mit der derzeit
2020/05/02 08:14:15 ui error: 2020-05-02T08:14:15+02:00: ==> vbox-base-win2012-r2: ausgeführten Windows PowerShell-Version 4.0 nicht überein.
2020/05/02 08:14:15 ui error: 2020-05-02T08:14:15+02:00: ==> vbox-base-win2012-r2: In Zeile:1 Zeichen:216
2020/05/02 08:14:15 ui error: 2020-05-02T08:14:15+02:00: ==> vbox-base-win2012-r2: + ... a075b0e4.ps1; &'C:/Windows/Temp/scripts/post-bootstrap.ps1'; exit
2020/05/02 08:14:15 ui error: 2020-05-02T08:14:15+02:00: ==> vbox-base-win2012-r2: $LastExitCode ...
2020/05/02 08:14:15 ui error: 2020-05-02T08:14:15+02:00: ==> vbox-base-win2012-r2: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2020/05/02 08:14:15 ui error: 2020-05-02T08:14:15+02:00: ==> vbox-base-win2012-r2: + CategoryInfo : ResourceUnavailable: (post-bootstrap.ps1:String)
2020/05/02 08:14:15 ui error: 2020-05-02T08:14:15+02:00: ==> vbox-base-win2012-r2: [], ScriptRequiresException
2020/05/02 08:14:15 ui error: 2020-05-02T08:14:15+02:00: ==> vbox-base-win2012-r2: + FullyQualifiedErrorId : ScriptRequiresUnmatchedPSVersion
2020/05/02 08:14:15 ui error: 2020-05-02T08:14:15+02:00: ==> vbox-base-win2012-r2:
2020/05/02 08:14:15 [INFO] 658 bytes written for 'stderr'
2020/05/02 08:14:15 [INFO] 0 bytes written for 'stdout'
2020/05/02 08:14:15 [INFO] RPC client: Communicator ended with: 0
2020/05/02 08:14:15 [INFO] RPC endpoint: Communicator ended with: 0
2020/05/02 08:14:15 packer.exe plugin: [INFO] 658 bytes written for 'stderr'
2020/05/02 08:14:15 packer.exe plugin: [INFO] 0 bytes written for 'stdout'
2020/05/02 08:14:15 packer.exe plugin: [INFO] RPC client: Communicator ended with: 0
2020/05/02 08:14:15 packer.exe plugin: C:/Windows/Temp/scripts/post-bootstrap.ps1 returned with exit code 0
Packer version
1.5.5
Operating system and Environment details
Packer Host: Windows Server 2019 (1809 LTS)
Virtualbox guest: Windows Server 2012 R2 (PowerShell v4)
Log Fragments and crash.log files
https://gist.github.com/Occams/099bb951b6a4074a3a4dbd5bea920cf0