hashicorp/vagrant · error · Vagrant::Errors::VagrantfileSyntaxError
There is a syntax error in the following Vagrantfile. The sy
Error message
There is a syntax error in the following Vagrantfile. The syntax error message is reproduced below for convenience:
%{file} What it means
Raised as Vagrant::Errors::VagrantfileSyntaxError from Config::Loader#procs_for_path (lib/vagrant/config/loader.rb:290) when Kernel.load(path) on the Vagrantfile raises SyntaxError — the file is not parseable Ruby. The raw Ruby parser message (which includes the file, line, and offending token) is passed through verbatim in the `file` placeholder, so users see Ruby's own diagnostic.
Source
Thrown at lib/vagrant/config/loader.rb:290
else
raise ArgumentError, "Unknown configuration source: #{reliably_inspected_sources[source]}"
end
end
# This returns an array of `Proc` objects for the given path source.
#
# @param [String] path Path to the file which contains the proper
# `Vagrant.configure` calls.
# @return [Array<Proc>]
def procs_for_path(path)
@logger.debug("Load procs for pathname: #{path}")
return Config.capture_configures do
begin
Kernel.load path
rescue SyntaxError => e
# Report syntax errors in a nice way.
raise Errors::VagrantfileSyntaxError, file: e.message
rescue SystemExit
# Continue raising that exception...
raise
rescue Vagrant::Errors::VagrantError
# Continue raising known Vagrant errors since they already
# contain well worded error messages and context.
raise
rescue Exception => e
@logger.error("Vagrantfile load error: #{e.message}")
@logger.error(e.backtrace.join("\n"))
line = "(unknown)"
if e.backtrace && e.backtrace[0]
e.backtrace[0].split(":").each do |part|
if part =~ /\d+/
line = part.to_i
break
endView on GitHub (pinned to 35f3160f4a)
Solutions
- Run `ruby -c Vagrantfile` to get the exact parser error and line number
- Fix the reported line — usually a missing or extra `end`, `do`, quote, or comma
- If the file is generated, fix the template/generator and regenerate rather than hand-patching
- Re-run `vagrant validate` to confirm the file parses before running real commands
Example fix
# before
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/jammy64"
# missing `end` for the configure block
# after
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/jammy64"
end Defensive patterns
Strategy: validation
Validate before calling
# Parse-check before any vagrant automation
out = `ruby -c Vagrantfile 2>&1`
abort "Vagrantfile syntax error:\n#{out}" unless $?.success? && out.include?("Syntax OK") Try / catch
begin
Vagrant::Environment.new(cwd: dir).vagrantfile
rescue Vagrant::Errors::VagrantfileSyntaxError => e
abort "Fix Vagrantfile syntax: #{e.extra_data[:file]}"
end Prevention
- Run `ruby -c Vagrantfile` after every manual edit
- Edit Vagrantfiles with a Ruby-aware editor so block structure is highlighted
- Keep generated Vagrantfiles under template tests so bad interpolation never reaches users
When it happens
Trigger: Any vagrant command in a project whose Vagrantfile (or the file being loaded as it) fails to parse: unbalanced end/do, unmatched quote, stray character, malformed heredoc, or a missing `do` keyword. The exception happens during Kernel.load before any config block is captured or evaluated.
Common situations: Hand-editing a Vagrantfile and dropping an `end`; git merges that break block structure; template/ERB generators emitting invalid Ruby; Windows line endings or smart quotes pasted from blog posts.
Related errors
- There was an error loading a Vagrantfile. The file being loa
- There was an error loading a Vagrantfile. The file being loa
- There was an error loading a Vagrantfile. The file being loa
- There are errors in the configuration of this machine. Pleas
- The specified Vagrantfile to clone from was not found. Pleas
AI-assisted analysis of hashicorp/vagrant@35f3160f4a (2026-08-21).
Data as JSON: /api/errors/aa84175dbcf1d1a0.
Report an issue: GitHub.