Quote powershell so that it does not try to interpret command to be run

Get VName out of state. This allows template replacement to be run on vmname
This commit is contained in:
Taliesin Sisson 2015-07-01 17:02:52 +01:00 committed by Taliesin Sisson
parent 6c3030c73a
commit 3051ea6633
4 changed files with 9 additions and 11 deletions

View File

@ -32,15 +32,14 @@ type bootCommandTemplateData struct {
type StepTypeBootCommand struct {
BootCommand []string
SwitchName string
VMName string
Ctx interpolate.Context
}
func (s *StepTypeBootCommand) Run(state multistep.StateBag) multistep.StepAction {
httpPort := state.Get("http_port").(uint)
ui := state.Get("ui").(packer.Ui)
driver := state.Get("driver").(Driver)
vmName := state.Get("vmName").(string)
hostIp, err := driver.GetHostAdapterIpAddressForSwitch(s.SwitchName)
@ -56,7 +55,7 @@ func (s *StepTypeBootCommand) Run(state multistep.StateBag) multistep.StepAction
s.Ctx.Data = &bootCommandTemplateData{
hostIp,
httpPort,
s.VMName,
vmName,
}
ui.Say("Typing the boot command...")
@ -77,7 +76,7 @@ func (s *StepTypeBootCommand) Run(state multistep.StateBag) multistep.StepAction
scanCodesToSendString := strings.Join(scanCodesToSend, " ")
if err := driver.TypeScanCodes(s.VMName, scanCodesToSendString); err != nil {
if err := driver.TypeScanCodes(vmName, scanCodesToSendString); err != nil {
err := fmt.Errorf("Error sending boot command: %s", err)
state.Put("error", err)
ui.Error(err.Error())

View File

@ -148,7 +148,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
}
if b.config.VMName == "" {
b.config.VMName = fmt.Sprintf("packer-%s", b.config.PackerBuildName)
b.config.VMName = fmt.Sprintf("packer-%s-{{timestamp}}", b.config.PackerBuildName)
}
log.Println(fmt.Sprintf("%s: %v", "VMName", b.config.VMName))
@ -311,7 +311,6 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&hypervcommon.StepTypeBootCommand{
BootCommand: b.config.BootCommand,
SwitchName: b.config.SwitchName,
VMName: b.config.VMName,
Ctx: b.config.ctx,
},

View File

@ -116,11 +116,11 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
}
if p.config.ElevatedEnvVarFormat == "" {
p.config.ElevatedEnvVarFormat = `$env:%s="%s"; `
p.config.ElevatedEnvVarFormat = `$env:%s=\"%s\"; `
}
if p.config.ExecuteCommand == "" {
p.config.ExecuteCommand = `powershell "& { {{.Vars}}{{.Path}}; exit $LastExitCode}"`
p.config.ExecuteCommand = `powershell '& { {{.Vars}}{{.Path}}; exit $LastExitCode}'`
}
if p.config.ElevatedExecuteCommand == "" {

View File

@ -75,8 +75,8 @@ func TestProvisionerPrepare_Defaults(t *testing.T) {
t.Error("expected elevated_password to be empty")
}
if p.config.ExecuteCommand != "powershell \"& { {{.Vars}}{{.Path}}; exit $LastExitCode}\"" {
t.Fatalf("Default command should be powershell \"& { {{.Vars}}{{.Path}}; exit $LastExitCode}\", but got %s", p.config.ExecuteCommand)
if p.config.ExecuteCommand != "powershell '& { {{.Vars}}{{.Path}}; exit $LastExitCode}'" {
t.Fatalf("Default command should be powershell '& { {{.Vars}}{{.Path}}; exit $LastExitCode}', but got %s", p.config.ExecuteCommand)
}
if p.config.ElevatedExecuteCommand != "{{.Vars}}{{.Path}}" {