{"record":{"id":"ff33e4b67fb7db66","repo":"hashicorp/packer","slug":"error-opening-shell-script-s","errorCode":null,"errorMessage":"Error opening shell script: %s","messagePattern":"Error opening shell script: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"provisioner/shell/provisioner.go","lineNumber":302,"sourceCode":"\t\t\tcmd.Wait()\n\t\t\tp.config.envVarFile = remoteVFName\n\t\t\treturn nil\n\t\t})\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\t// Create environment variables to set before executing the command\n\tflattenedEnvVars := p.createFlattenedEnvVars()\n\n\tfor _, path := range scripts {\n\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,","sourceCodeStart":284,"sourceCodeEnd":320,"githubUrl":"https://github.com/hashicorp/packer/blob/eb36e3c3e48a036f3e8cc94087636ee72e1303c9/provisioner/shell/provisioner.go#L284-L320","documentation":"Provision iterates over the resolved script paths (inline-generated temp scripts plus configured script files) and opens each locally to upload it (provisioner/shell/provisioner.go:302). This error means os.Open(path) on a script file failed — the file does not exist at that path, is unreadable, or the path is a directory. For temp inline scripts this indicates the temp file was removed early; for user scripts it is almost always a bad path in the template.","triggerScenarios":"script or scripts entries point to files that don't exist relative to the packer run directory; the file exists on the machine where the template was edited but not where packer runs (CI checkout mismatch); a symlink target is missing; permissions deny read.","commonSituations":"Wrong relative path in the shell provisioner's scripts list; running packer from a different working directory than expected in CI; files not checked into the repo; Windows path separators vs Unix; case-sensitivity mismatch on Linux.","solutions":["Verify each path in scripts exists relative to where packer is invoked (ls -l <path>).","Use absolute paths or correct the working directory in CI before running packer.","Ensure script files are committed/copied into the CI workspace.","Fix file permissions (chmod +r) or replace broken symlinks.","On case-sensitive filesystems, match the filename case exactly."],"exampleFix":"// before\nprovisioner \"shell\" {\n  scripts = [\"./scripts/setup.sh\"]\n}\n// after — path verified from the template's directory\nprovisioner \"shell\" {\n  scripts = [\"${path.root}/scripts/setup.sh\"]\n}","handlingStrategy":"validation","validationCode":"// validate all script paths before invoking packer\nfor f in scripts/setup.sh scripts/bootstrap.sh; do\n  [ -f \"$f\" ] && [ -r \"$f\" ] || { echo \"missing/unreadable script: $f\"; exit 1; }\ndone\npacker build template.pkr.hcl","typeGuard":null,"tryCatchPattern":"// if invoking provisioner programmatically\nf, err := os.Open(path)\nif err != nil {\n    if os.IsNotExist(err) {\n        return fmt.Errorf(\"script %q not found; check scripts[] paths relative to cwd\", path)\n    }\n    return err\n}","preventionTips":["Reference scripts with ${path.root}/ so paths resolve relative to the template.","Commit all referenced scripts to the repo and verify CI checkouts include them.","Run packer from the directory you expect; log pwd in CI before building.","Check for broken symlinks and case mismatches on case-sensitive filesystems."],"tags":["provisioner","shell","file-not-found","path"],"backgroundTag":"file-not-found","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"}