diff --git a/post-processor/shell-local/post-processor.go b/post-processor/shell-local/post-processor.go index 6ed9b0a89..45c9ddb85 100644 --- a/post-processor/shell-local/post-processor.go +++ b/post-processor/shell-local/post-processor.go @@ -4,13 +4,14 @@ import ( "bufio" "errors" "fmt" + "io/ioutil" + "os" + "strings" + "github.com/mitchellh/packer/common" "github.com/mitchellh/packer/helper/config" "github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/template/interpolate" - "io/ioutil" - "os" - "strings" ) type Config struct { @@ -46,8 +47,9 @@ type PostProcessor struct { } type ExecuteCommandTemplate struct { - Vars string - Path string + Vars string + Script string + Artifact string } func (p *PostProcessor) Configure(raws ...interface{}) error { @@ -65,7 +67,7 @@ func (p *PostProcessor) Configure(raws ...interface{}) error { } if p.config.ExecuteCommand == "" { - p.config.ExecuteCommand = "chmod +x {{.Path}}; {{.Vars}} {{.Path}}" + p.config.ExecuteCommand = "chmod +x {{.Script}}; {{.Vars}} {{.Script}} {{.Artifact}}" } if p.config.Inline != nil && len(p.config.Inline) == 0 { @@ -171,14 +173,14 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac copy(envVars[2:], p.config.Vars) for _, file := range artifact.Files() { - for _, path := range scripts { + for _, script := range scripts { // Flatten the environment variables flattendVars := strings.Join(envVars, " ") - path := strings.Join([]string{path, file}, " ") p.config.ctx.Data = &ExecuteCommandTemplate{ - Vars: flattendVars, - Path: path, + Vars: flattendVars, + Script: script, + Artifact: file, } command, err := interpolate.Render(p.config.ExecuteCommand, &p.config.ctx) @@ -194,19 +196,19 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac ui.Say(fmt.Sprintf( "Executing local script: %s", - path)) + script)) if err := cmd.StartWithUi(comm, ui); err != nil { return nil, false, fmt.Errorf( "Error executing script: %s\n\n"+ "Please see output above for more information.", - path) + script) } if cmd.ExitStatus != 0 { return nil, false, fmt.Errorf( "Erroneous exit code %d while executing script: %s\n\n"+ "Please see output above for more information.", cmd.ExitStatus, - path) + script) } } } diff --git a/website/source/docs/post-processors/shell-local.html.md b/website/source/docs/post-processors/shell-local.html.md index 1ff50bde2..04cb49c09 100644 --- a/website/source/docs/post-processors/shell-local.html.md +++ b/website/source/docs/post-processors/shell-local.html.md @@ -54,11 +54,11 @@ Optional parameters: as well, which are covered in the section below. - `execute_command` (string) - The command to use to execute the script. By - default this is `chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}`. The value - of this is treated as [configuration - template](/docs/templates/configuration-templates.html). There are two - available variables: `Path`, which is the path to the script to run, and - `Vars`, which is the list of `environment_vars`, if configured. + default this is `chmod +x {{.Script}}; {{.Vars}} {{.Script}} {{.Artifact}}`. + The value of this is treated as [configuration template](/docs/templates/configuration-templates.html). + There are three available variables: `Script`, which is the path to the script + to run, `Vars`, which is the list of `environment_vars`, if configured and + `Artifact`, which is path to artifact file. - `inline_shebang` (string) - The [shebang](http://en.wikipedia.org/wiki/Shebang_%28Unix%29) value to use when