hashicorp/packer · error
Either a script file or inline script must be specified.
Error message
Either a script file or inline script must be specified.
What it means
After normalizing script into scripts, Prepare requires the provisioner to have something to execute: either at least one entry in scripts or an inline script array. If both are empty there is no work to do, so the template is rejected. This catches provisioner blocks that exist but configure no actual PowerShell payload.
Source
Thrown at provisioner/powershell/provisioner.go:240
var errs error
if p.config.Script != "" && len(p.config.Scripts) > 0 {
errs = packersdk.MultiErrorAppend(errs,
errors.New("Only one of script or scripts can be specified."))
}
if p.config.ElevatedUser == "" && p.config.ElevatedPassword != "" {
errs = packersdk.MultiErrorAppend(errs,
errors.New("Must supply an 'elevated_user' if 'elevated_password' provided"))
}
if p.config.Script != "" {
p.config.Scripts = []string{p.config.Script}
}
if len(p.config.Scripts) == 0 && p.config.Inline == nil {
errs = packersdk.MultiErrorAppend(errs,
errors.New("Either a script file or inline script must be specified."))
} else if len(p.config.Scripts) > 0 && p.config.Inline != nil {
errs = packersdk.MultiErrorAppend(errs,
errors.New("Only a script file or an inline script can be specified, not both."))
}
if p.config.ExecuteCommand == "" {
if p.config.Inline != nil && len(p.config.Scripts) == 0 {
p.config.ExecuteCommand = p.defaultExecuteCommand()
log.Printf("Using inline default execute command %s", p.config.ExecuteCommand)
} else {
p.config.ExecuteCommand = p.defaultScriptCommand()
log.Printf("Using script default execute command %s", p.config.ExecuteCommand)
}
}
if p.config.ElevatedExecuteCommand == "" {
if p.config.Inline != nil && len(p.config.Scripts) == 0 {View on GitHub (pinned to eb36e3c3e4)
Solutions
- Set scripts = ["path/to/script.ps1"] (or script for a single file).
- Or provide inline = ["Write-Host 'hello'"] for ad-hoc commands.
- Verify variables feeding scripts/inline are non-empty for this build target.
Example fix
// before
provisioner "powershell" {
elevated_user = "Administrator"
}
// after
provisioner "powershell" {
scripts = ["./setup.ps1"]
elevated_user = "Administrator"
} Defensive patterns
Strategy: validation
Validate before calling
// Ensure the block has a payload before building:
// scripts.len > 0 || inline != null
assert {
condition = length(var.ps_scripts) > 0 || length(var.ps_inline) > 0
error_message = "powershell provisioner needs script(s) or inline."
} Prevention
- Never leave a provisioner block as an empty stub; scaffold it with at least one inline entry.
- Verify variables feeding scripts/inline are populated for all target builds.
- Run packer validate as part of CI.
When it happens
Trigger: A powershell provisioner block with neither script(s) nor inline set; or script/scripts/inline all sourced from empty variables at build time (e.g. scripts = var.script_list where var.script_list is []).
Common situations: Scaffolding a provisioner block before writing the script; templating where the script variable is empty for a given build; commenting out the script line during debugging and forgetting to restore it.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Only one of script or scripts can be specified.
- Must supply an 'elevated_user' if 'elevated_password' provid
- Only a script file or an inline script can be specified, not
- source must be specified when auto_generate is not enabled
- Only one of script or scripts can be specified.
AI-assisted analysis of hashicorp/packer@eb36e3c3e4 (2026-09-05).
Data as JSON: /api/errors/32e03a9ff7a8f9e3.
Report an issue: GitHub.