Skip to content

Commit 6148229

Browse files
committed
Merge pull request hashicorp#5751 from hashicorp/phinze/fixup-remote-exec
provisioner/remote-exec: Move script cleanup after command wait
2 parents 7e3e3b2 + 579680c commit 6148229

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

builtin/provisioners/remote-exec/resource_provisioner.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,8 @@ func (p *ResourceProvisioner) runScripts(
176176
go p.copyOutput(o, outR, outDoneCh)
177177
go p.copyOutput(o, errR, errDoneCh)
178178

179+
remotePath := comm.ScriptPath()
179180
err = retryFunc(comm.Timeout(), func() error {
180-
remotePath := comm.ScriptPath()
181181

182182
if err := comm.UploadScript(remotePath, script); err != nil {
183183
return fmt.Errorf("Failed to upload script: %v", err)
@@ -192,13 +192,6 @@ func (p *ResourceProvisioner) runScripts(
192192
return fmt.Errorf("Error starting script: %v", err)
193193
}
194194

195-
// Upload a blank follow up file in the same path to prevent residual
196-
// script contents from remaining on remote machine
197-
empty := bytes.NewReader([]byte(""))
198-
if err := comm.Upload(remotePath, empty); err != nil {
199-
return fmt.Errorf("Failed to upload empty follow up script: %v", err)
200-
}
201-
202195
return nil
203196
})
204197
if err == nil {
@@ -214,6 +207,14 @@ func (p *ResourceProvisioner) runScripts(
214207
<-outDoneCh
215208
<-errDoneCh
216209

210+
// Upload a blank follow up file in the same path to prevent residual
211+
// script contents from remaining on remote machine
212+
empty := bytes.NewReader([]byte(""))
213+
if err := comm.Upload(remotePath, empty); err != nil {
214+
// This feature is best-effort.
215+
log.Printf("[WARN] Failed to upload empty follow up script: %v", err)
216+
}
217+
217218
// If we have an error, return it out now that we've cleaned up
218219
if err != nil {
219220
return err

0 commit comments

Comments
 (0)