diff --git a/provisioner/shell/provisioner.go b/provisioner/shell/provisioner.go index c2ae4d938..2f64759b9 100644 --- a/provisioner/shell/provisioner.go +++ b/provisioner/shell/provisioner.go @@ -270,16 +270,25 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error { return fmt.Errorf("Script exited with non-zero exit status: %d", cmd.ExitStatus) } - // Delete the temporary file we created - cmd = &packer.RemoteCmd{ - Command: fmt.Sprintf("rm -f %s", p.config.RemotePath), - } - if err := comm.Start(cmd); err != nil { - return fmt.Errorf( - "Error removing temporary script at %s: %s", - p.config.RemotePath, err) + // Delete the temporary file we created. We retry this a few times + // since if the above rebooted we have to wait until the reboot + // completes. + err = p.retryable(func() error { + cmd = &packer.RemoteCmd{ + Command: fmt.Sprintf("rm -f %s", p.config.RemotePath), + } + if err := comm.Start(cmd); err != nil { + return fmt.Errorf( + "Error removing temporary script at %s: %s", + p.config.RemotePath, err) + } + cmd.Wait() + return nil + }) + if err != nil { + return err } - cmd.Wait() + if cmd.ExitStatus != 0 { return fmt.Errorf( "Error removing temporary script at %s!",