hashicorp/packer · error

Error processing command: %s

Error message

Error processing command: %s

What it means

Provision calls p.createCommandText() to build the remote PowerShell command line (which interpolates environment vars, elevated-run settings, and generated data into the command). Any failure inside that rendering returns "Error processing command: %s", aborting before upload/execution.

Source

Thrown at provisioner/powershell/provisioner.go:381

		log.Printf("Opening %s for reading", path)
		fi, err := os.Stat(path)
		if err != nil {
			return fmt.Errorf("Error stating powershell script: %s", err)
		}
		if os.IsPathSeparator(p.config.RemotePath[len(p.config.RemotePath)-1]) {
			// path is a directory
			p.config.RemotePath += filepath.Base(fi.Name())
		}
		f, err := os.Open(path)
		if err != nil {
			return fmt.Errorf("Error opening powershell script: %s", err)
		}
		defer f.Close()

		command, err := p.createCommandText()
		if err != nil {
			return fmt.Errorf("Error processing command: %s", err)
		}

		// Upload the file and run the command. Do this in the context of a
		// single retryable function so that we don't end up with the case
		// that the upload succeeded, a restart is initiated, and then the
		// command is executed but the file doesn't exist any longer.
		var cmd *packersdk.RemoteCmd
		err = retry.Config{StartTimeout: p.config.StartRetryTimeout}.Run(ctx, func(ctx context.Context) error {
			if _, err := f.Seek(0, 0); err != nil {
				return err
			}
			if err := comm.Upload(p.config.RemotePath, f, &fi); err != nil {
				return fmt.Errorf("Error uploading script: %s", err)
			}

			cmd = &packersdk.RemoteCmd{Command: command}
			return cmd.RunWithUi(ctx, comm, ui)
		})

View on GitHub (pinned to eb36e3c3e4)

Solutions

  1. Read the wrapped cause and fix the offending template expression in environment_vars or related config.
  2. Escape literal '{{'/'}}' sequences in variable values ({{`{{`}}) so they are not parsed as Go templates.
  3. Only reference generated data keys documented for your Packer version.
  4. Bisect by simplifying environment_vars/elevated settings until the render succeeds, then restore pieces one at a time.

Example fix

// before
environment_vars = ["HOST={{ .IP }}"]  // .IP not in context
// after
environment_vars = ["HOST={{ build `Name` }}"]
Defensive patterns

Strategy: try-catch

Validate before calling

// Before building, sanity-check env var values for Go-template syntax
for _, kv := range cfg.Vars {
    if strings.Contains(kv, "{{") && !strings.Contains(kv, "{{ `") {
        log.Printf("env var %q contains interpolation; verify keys exist in generated data", kv)
    }
}

Try / catch

// Go
err := prov.Provision(ctx, ui, comm, genData)
if err != nil && strings.Contains(err.Error(), "Error processing command") {
    fmt.Fprintf(os.Stderr, "command rendering failed: %v\n", err)
    // simplify environment_vars / elevated settings, escape {{ }}, retry
}

Prevention

When it happens

Trigger: Provision called when createCommandText's interpolate.Render fails — typically invalid template syntax in env vars, elevated_user/elevated_password, or incompatible generated-data usage in the command template.

Common situations: Environment variable values containing Go-template '{{' sequences; references to build-generated data (e.g. {{ .ID }}) in positions where the data isn't present; malformed quoting in elevated_password causing render errors; Packer version differences in available context keys.

Related errors


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