{"record":{"id":"320cb7e35217a546","repo":"hashicorp/packer","slug":"error-processing-command-s-320cb7","errorCode":null,"errorMessage":"Error processing command: %s","messagePattern":"Error processing command: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"provisioner/shell/provisioner.go","lineNumber":315,"sourceCode":"\t\tui.Say(fmt.Sprintf(\"Provisioning with shell script: %s\", path))\n\n\t\tlog.Printf(\"Opening %s for reading\", path)\n\t\tf, err := os.Open(path)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"Error opening shell script: %s\", err)\n\t\t}\n\t\tdefer f.Close()\n\n\t\t// Compile the command\n\t\t// These are extra variables that will be made available for interpolation.\n\t\tgeneratedData[\"Vars\"] = flattenedEnvVars\n\t\tgeneratedData[\"EnvVarFile\"] = p.config.envVarFile\n\t\tgeneratedData[\"Path\"] = p.config.RemotePath\n\t\tp.config.ctx.Data = generatedData\n\n\t\tcommand, err := interpolate.Render(p.config.ExecuteCommand, &p.config.ctx)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"Error processing command: %s\", err)\n\t\t}\n\n\t\t// Upload the file and run the command. Do this in the context of\n\t\t// a single retryable function so that we don't end up with\n\t\t// the case that the upload succeeded, a restart is initiated,\n\t\t// and then the command is executed but the file doesn't exist\n\t\t// any longer.\n\t\tvar cmd *packersdk.RemoteCmd\n\t\terr = retry.Config{StartTimeout: p.config.StartRetryTimeout}.Run(ctx, func(ctx context.Context) error {\n\t\t\tif _, err := f.Seek(0, 0); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\n\t\t\tvar r io.Reader = f\n\t\t\tif !p.config.Binary {\n\t\t\t\tr = &UnixReader{Reader: r}\n\t\t\t}\n","sourceCodeStart":297,"sourceCodeEnd":333,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/provisioner/shell/provisioner.go#L297-L333","documentation":"The shell provisioner renders the user-supplied `execute_command` HCL/Go template (with generated data like .Path, .Vars, .EnvVarFile) before running it on the remote machine. If template interpolation fails — e.g. a syntax error or a reference to an unknown variable/sprig function — Provision aborts with this message wrapping the underlying render error. It is thrown before anything is uploaded, so no remote state was changed.","triggerScenarios":"Calling provision (via `packer build`) with an execute_command containing invalid template syntax such as `{{` without closing braces, an unknown template function like `{{ .Foo }}` when Foo is not a provided variable, or invalid sprig pipeline usage.","commonSituations":"Typo'd template variables (e.g. `{{ .Pathy }}` instead of `{{ .Path }}`); copying a command with `{{.Vars}}` into a context where env vars were not defined; hand-edited templates with unbalanced `{{` `}}`; mixing legacy JSON template syntax with HCL2 variables.","solutions":["Fix the template syntax in execute_command — check for balanced {{ }} braces","Use only the provided variables: .Path, .Vars, .EnvVarFile (and configured template variables)","Run `packer validate` / `packer inspect` to catch template errors before a build","If using custom env vars, ensure they are defined so {{ .Vars }} renders correctly"],"exampleFix":"// before\nexecute_command = \"chmod +x {{ .Pathy }}; {{ .Pathy }}\"\n// after\nexecute_command = \"chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}\"","handlingStrategy":"validation","validationCode":"# Validate the template renders before a build; catch bad vars/braces early.\nexecute_command = \"chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}\"\n# then:\n# packer validate template.pkr.hcl","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only reference generated variables Packer provides (.Path, .Vars, .EnvVarFile) unless you added custom ones","Keep execute_command templates simple; test complex logic inside the script file itself","Run packer validate/inspect before builds to catch template syntax errors","Avoid hand-copying {{ }} snippets from other templates without checking variable names"],"tags":["provisioner","shell","template-interpolation","hcl2"],"backgroundTag":"template-interpolation-error","analyzedSha":"eb36e3c3e48a036f3e8cc94087636ee72e1303c9","analyzedAt":"2026-09-05T13:20:43.127Z","contentChangedAt":"2026-09-05T13:20:43.127Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}