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

with_target_vms in a v1 command received a slash-wrapped regex target (`vagrant <cmd> /pattern/`), iterated all VM names in the Vagrantfile, and matched none of them (lib/vagrant/plugin/v1/command.rb:92). The pattern is compiled with Ruby's Regexp.new and is unanchored by default, so it matches anywhere in the machine name.

Source

Thrown at lib/vagrant/plugin/v1/command.rb:92

          # Require that names be an array
          names ||= []
          names = [names] if !names.is_a?(Array)

          # First determine the proper array of VMs.
          vms = []
          if names.length > 0
            names.each do |name|
              if pattern = name[/^\/(.+?)\/$/, 1]
                # This is a regular expression name, so we convert to a regular
                # expression and allow that sort of matching.
                regex = Regexp.new(pattern)

                @env.vms.each do |name, vm|
                  vms << vm if name =~ regex
                end

                raise Errors::VMNoMatchError if vms.empty?
              else
                # String name, just look for a specific VM
                vms << @env.vms[name.to_sym]
                raise Errors::VMNotFoundError, name: name if !vms[0]
              end
            end
          else
            vms = @env.vms_ordered
          end

          # Make sure we're only working with one VM if single target
          if options[:single_target] && vms.length != 1
            vm = @env.primary_vm
            raise Errors::MultiVMTargetRequired if !vm
            vms = [vm]
          end

          # If we asked for reversed ordering, then reverse it

View on GitHub (pinned to 35f3160f4a)

Solutions

  1. List the actual machine names with `vagrant status` or by reading the config.vm.define calls in the Vagrantfile
  2. Fix the pattern — anchor it explicitly if you want prefix matching, e.g. /^web-/
  3. Use an exact machine name instead of a regex when you only need one machine

Example fix

# before (machine names are web-1, web-2)
vagrant destroy /webserver/

# after
vagrant destroy /web-/
Defensive patterns

Strategy: validation

Validate before calling

pattern = "web"
names = env.vms.keys.map(&:to_s)
abort "no VM name matches /#{pattern}/; valid: #{names.join(', ')}" unless names.any? { |n| n =~ /#{pattern}/ }

Prevention

When it happens

Trigger: For example `vagrant destroy /webserver/` in an environment whose machines are named web-1, web-2, db — zero matches raise before the command runs. Also regex metacharacter mistakes (`/web+/` matching nothing as expected) or an environment where the named group of machines was removed.

Common situations: Pattern written for full names when Vagrantfile uses abbreviated or hyphenated names; Vagrantfile refactored so the pattern's target machines no longer exist; copy-pasting a pattern from another project's docs.

Related errors


AI-assisted analysis of hashicorp/vagrant@35f3160f4a (2026-08-21). Data as JSON: /api/errors/7358e9a0635c5e64. Report an issue: GitHub.