diff --git a/builtin/provisioners/remote-exec/resource_provisioner.go b/builtin/provisioners/remote-exec/resource_provisioner.go index f3524a31ce..2f784a4eaa 100644 --- a/builtin/provisioners/remote-exec/resource_provisioner.go +++ b/builtin/provisioners/remote-exec/resource_provisioner.go @@ -176,8 +176,8 @@ func (p *ResourceProvisioner) runScripts( go p.copyOutput(o, outR, outDoneCh) go p.copyOutput(o, errR, errDoneCh) + remotePath := comm.ScriptPath() err = retryFunc(comm.Timeout(), func() error { - remotePath := comm.ScriptPath() if err := comm.UploadScript(remotePath, script); err != nil { return fmt.Errorf("Failed to upload script: %v", err) @@ -192,13 +192,6 @@ func (p *ResourceProvisioner) runScripts( return fmt.Errorf("Error starting script: %v", err) } - // Upload a blank follow up file in the same path to prevent residual - // script contents from remaining on remote machine - empty := bytes.NewReader([]byte("")) - if err := comm.Upload(remotePath, empty); err != nil { - return fmt.Errorf("Failed to upload empty follow up script: %v", err) - } - return nil }) if err == nil { @@ -214,6 +207,14 @@ func (p *ResourceProvisioner) runScripts( <-outDoneCh <-errDoneCh + // Upload a blank follow up file in the same path to prevent residual + // script contents from remaining on remote machine + empty := bytes.NewReader([]byte("")) + if err := comm.Upload(remotePath, empty); err != nil { + // This feature is best-effort. + log.Printf("[WARN] Failed to upload empty follow up script: %v", err) + } + // If we have an error, return it out now that we've cleaned up if err != nil { return err