hashicorp/vagrant · error · Vagrant::Errors::VMNoMatchError
No virtual machines matched the regular expression given.
Error message
No virtual machines matched the regular expression given.
What it means
v2 counterpart of the v1 regex error: a slash-delimited target (`vagrant <cmd> /pattern/`) was compiled and matched against env.machine_names, and no configured machine name matched, so the guard at lib/vagrant/plugin/v2/command.rb:203 raised before any machine was yielded. The pattern is plain Ruby Regexp, unanchored by default.
Source
Thrown at lib/vagrant/plugin/v2/command.rb:203
# First determine the proper array of VMs.
machines = []
if names.length > 0
names.each do |name|
if pattern = name[/^\/(.+?)\/$/, 1]
@logger.debug("Finding machines that match regex: #{pattern}")
# This is a regular expression name, so we convert to a regular
# expression and allow that sort of matching.
regex = Regexp.new(pattern)
@env.machine_names.each do |machine_name|
if machine_name =~ regex
machines << get_machine.call(machine_name)
end
end
raise Errors::VMNoMatchError if machines.empty?
else
# String name, just look for a specific VM
@logger.debug("Finding machine that match name: #{name}")
machines << get_machine.call(name.to_sym)
raise Errors::VMNotFoundError, name: name if !machines[0]
end
end
else
# No name was given, so we return every VM in the order
# configured.
@logger.debug("Loading all machines...")
machines = @env.machine_names.map do |machine_name|
get_machine.call(machine_name)
end
end
@logger.debug("have machine list to process")
View on GitHub (pinned to 35f3160f4a)
Solutions
- List valid machine names via `vagrant status` or the config.vm.define blocks
- Fix and anchor the pattern explicitly, e.g. /^web-/
- Use exact machine names in scripts; keep regex selectors for interactive use
Example fix
# before (machines are web-1, web-2) vagrant destroy /^webserver/ # after vagrant destroy /^web-/
Defensive patterns
Strategy: validation
Validate before calling
pattern = "^web-"
names = env.machine_names.map(&:to_s)
abort "no machine matches /#{pattern}/; valid: #{names.join(', ')}" unless names.any? { |n| n =~ /#{pattern}/ } Prevention
- Anchor regex selectors (/^web-/) rather than relying on substring matching
- Verify machine names with `vagrant status` after refactoring a Vagrantfile
- Prefer exact names in automation; use regex selectors interactively
When it happens
Trigger: `vagrant up /app-/` in a project whose machines are named web and db; a pattern written for full names when defines use hyphenated names; a regex with an escaping mistake that matches nothing.
Common situations: Machine names refactored after the pattern was written; patterns copied between projects; assuming anchoring semantics that were never specified.
Related errors
- A VM by the name of %{name} was not found.
- This command requires a specific VM name to target in a mult
- No virtual machines matched the regular expression given.
- An invalid option was specified. The help for this command i
- You requested to remove the box '%{name}' version '%{version
AI-assisted analysis of hashicorp/vagrant@35f3160f4a (2026-08-21).
Data as JSON: /api/errors/9e0b7bee302e232a.
Report an issue: GitHub.