hashicorp/packer · error

Error removing temporary script at %s: %s

Error message

Error removing temporary script at %s: %s

What it means

During cleanup the provisioner runs `rm -f <path>` on the remote host to delete the temporary uploaded script. If comm.Start fails to launch that command (connection error, shell unavailable), the error is wrapped as this message and returned from the retryable cleanup loop. Because `rm -f` is best-effort, this failure indicates a communicator-level problem, not a missing file.

Source

Thrown at provisioner/shell/provisioner.go:404

		}
	}

	if p.config.PauseAfter != 0 {
		ui.Say(fmt.Sprintf("Pausing %s after this provisioner...", p.config.PauseAfter))
		time.Sleep(p.config.PauseAfter)
	}

	return nil
}

func (p *Provisioner) cleanupRemoteFile(path string, comm packersdk.Communicator) error {
	ctx := context.TODO()
	err := retry.Config{StartTimeout: p.config.StartRetryTimeout}.Run(ctx, func(ctx context.Context) error {
		cmd := &packersdk.RemoteCmd{
			Command: fmt.Sprintf("rm -f %s", path),
		}
		if err := comm.Start(ctx, cmd); err != nil {
			return fmt.Errorf(
				"Error removing temporary script at %s: %s",
				path, err)
		}
		cmd.Wait()
		// treat disconnects as retryable by returning an error
		if cmd.ExitStatus() == packersdk.CmdDisconnect {
			return fmt.Errorf("Disconnect while removing temporary script.")
		}
		if cmd.ExitStatus() != 0 {
			return fmt.Errorf(
				"Error removing temporary script at %s!",
				path)
		}
		return nil
	})

	if err != nil {
		return err

View on GitHub (pinned to eb36e3c3e4)

Solutions

  1. Ensure the machine is fully back up after any script-triggered reboot before provisioning ends (the built-in retry helps — give it time via start_retry_timeout)
  2. Verify communicator connectivity (SSH/WinRM reachable, correct ports/security groups)
  3. Use skip_clean = true if cleanup is not required for your workflow
  4. Re-run the build; this often clears once the host is stable

Example fix

// before
provisioner "shell" {
  scripts = ["reboot.sh"]
  expect_disconnect = true
}
// after
provisioner "shell" {
  scripts = ["reboot.sh"]
  expect_disconnect = true
  skip_clean = true
}
Defensive patterns

Strategy: retry

Try / catch

err := retry.Config{StartTimeout: p.config.StartRetryTimeout}.Run(ctx, func(ctx context.Context) error {
    if err := comm.Start(ctx, cmd); err != nil {
        return fmt.Errorf("Error removing temporary script at %s: %s", path, err)
    }
    return nil
})

Prevention

When it happens

Trigger: comm.Start(ctx, cmd) failing while running `rm -f <RemotePath>` in cleanupRemoteFile — dropped SSH/WinRM session, unreachable host after a reboot triggered by the script, or communicator channel error.

Common situations: Machine was rebooted by the script and is still coming up when cleanup runs; network flakiness at end of provisioning; sshd rate limiting; WinRM session limits.

Related errors


AI-assisted analysis of hashicorp/packer@eb36e3c3e4 (2026-09-05). Data as JSON: /api/errors/43f8f966b0ca6ff2. Report an issue: GitHub.