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

shell-local post-processor results in errors on Windows #4140

Closed
mrled opened this issue Nov 9, 2016 · 10 comments
Closed

shell-local post-processor results in errors on Windows #4140

mrled opened this issue Nov 9, 2016 · 10 comments

Comments

@mrled
Copy link

mrled commented Nov 9, 2016

When I try to use the shell-local post-processor in Windows, it fails with an empty error message.

Is this working under Windows? Have I done something wrong?

@mwhooker
Copy link
Contributor

confirmed this.

the problem seems to be that powershell.exe won't run any file that doesn't end in ".ps1" and we write the script to something like packer-shell123456

@mrled
Copy link
Author

mrled commented Nov 10, 2016

Hmm. That might be part of the problem too, but I'm also seeing it when trying to run a Python script, and Python isn't constrained to only running files with certain extensions. I've updated my gist with a Python script and its output. It has the same empty error message.

@mwhooker
Copy link
Contributor

alright I think the problem is that the post-processor communicator uses exec.Command("sh", "-c", cmd.Command).

I manually changed it to use exec.Command("Powershell.exe", "-command", cmd.Command) and made the execute_command something like Move-Item {{.Script}} {{.Script}}.ps1; Powershell.exe -File {{.Script}}.ps1 and it worked. Need to figure out how to abstract this for the windows host

@mwhooker mwhooker added this to the v1.0 milestone Nov 10, 2016
@rickard-von-essen
Copy link
Collaborator

Maybe we should have a powershell-local post-processor. But on the other
hand we have our doubts about the shell-local since it ties the
configuration tighter to the setup/type of host running the build.

On Nov 10, 2016 01:57, "Matthew Hooker" notifications@github.com wrote:

alright I think the problem is that the post-processor communicator
uses exec.Command("sh",
"-c", cmd.Command).

I manually changed it to use exec.Command("Powershell.exe", "-command",
cmd.Command) and made the execute_command something like Move-Item
{{.Script}} {{.Script}}.ps1; Powershell.exe -File {{.Script}}.ps1 and it
worked. Need to figure out how to abstract this for the windows host


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#4140 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAiCg2lYBi3kB0OO_bfUyV2J0ztswbnqks5q8mvygaJpZM4KuDHt
.

@mrled
Copy link
Author

mrled commented Nov 11, 2016

Hmm. Well I hope it, or something like it, stays around, because I've found it to be very useful. A powershell-local (or cmd-local, which I could use to invoke Powershell or any other scripting language myself) would definitely solve my problem too.

@vtolstov
Copy link
Contributor

I thinks we can change default for each builder....

@damphyr
Copy link

damphyr commented Dec 21, 2016

I've stumbled on this trying to get .msu files to execute.

Basically I'm trying to get a Vagrant Win7 basebox without the dreaded 100% CPU windows update bug and that involves installing three .msu files with in-between reboots just so we can run windows update again. But wusa.exe does not allow .msu execution over winRM so I thought I would do it locally - hence my landing here.

I switched back to

{
      "type": "shell-local",
      "execute_command": ["cmd.exe","/C","{{.Command}}"],
      "command": "echo Boo"
}

as a workaround but I'm not having much success with it either.
Without a local execution context the only workaround I have left is creating schedule tasks to run on reboot and triggering reboots :(

@mwhooker mwhooker modified the milestones: v1.1, v1.0 Mar 10, 2017
@mwhooker mwhooker modified the milestones: v1.0.2, v1.0.1 May 16, 2017
@SwampDragons
Copy link
Contributor

SwampDragons commented Jul 6, 2017

It seems to me that the point of having an "execute_command" option is to allow the entire command to be configurable. So why not wait until we can make a backwards-breaking change, and then entirely remove the assumption of a shell command? This seems to me to be the way the feature is documented, anyway.

For example (pardon the naive string handling, was just pounding this out to see if it'd work):

--- a/post-processor/shell-local/communicator.go
+++ b/post-processor/shell-local/communicator.go
@@ -5,6 +5,7 @@ import (
        "io"
        "os"
        "os/exec"
+       "strings"
        "syscall"

        "github.com/hashicorp/packer/packer"
@@ -13,7 +14,10 @@ import (
 type Communicator struct{}

 func (c *Communicator) Start(cmd *packer.RemoteCmd) error {
-       localCmd := exec.Command("sh", "-c", cmd.Command)
+       splitcmd := strings.Split(cmd.Command, " ")
+       cmdName := splitcmd[0]
+       cmdArgs := strings.Join(splitcmd[1:], " ")
+       localCmd := exec.Command(cmdName, cmdArgs)

Which you can then use a provisioner with like this:

> "post-processors": [
>     {
>       "type": "shell-local",
>       "execute_command": "Powershell.exe Move-Item {{.Script}} {{.Script}}.ps1; Powershell.exe -File {{.Script}}.ps1",
>       "inline": ["write-output HIIIIIIIII"]
>     }

@mwhooker mwhooker modified the milestones: v1.1.1, v1.0.3 Aug 7, 2017
@SwampDragons
Copy link
Contributor

Closing because we have decided to deprecate this post-processor instead of fixing it; #5330

@ghost
Copy link

ghost commented Apr 3, 2020

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.

@ghost ghost locked and limited conversation to collaborators Apr 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants