{"record":{"id":"e99e92f2e7bb64aa","repo":"hashicorp/vagrant","slug":"this-command-requires-a-specific-vm-name-to-target","errorCode":null,"errorMessage":"This command requires a specific VM name to target in a multi-VM environment.","messagePattern":"This command requires a specific VM name to target in a multi-VM environment\\.","errorType":"exception","errorClass":"Vagrant::Errors::MultiVMTargetRequired","httpStatus":null,"severity":"error","filePath":"lib/vagrant/plugin/v1/command.rb","lineNumber":106,"sourceCode":"                @env.vms.each do |name, vm|\n                  vms << vm if name =~ regex\n                end\n\n                raise Errors::VMNoMatchError if vms.empty?\n              else\n                # String name, just look for a specific VM\n                vms << @env.vms[name.to_sym]\n                raise Errors::VMNotFoundError, name: name if !vms[0]\n              end\n            end\n          else\n            vms = @env.vms_ordered\n          end\n\n          # Make sure we're only working with one VM if single target\n          if options[:single_target] && vms.length != 1\n            vm = @env.primary_vm\n            raise Errors::MultiVMTargetRequired if !vm\n            vms = [vm]\n          end\n\n          # If we asked for reversed ordering, then reverse it\n          vms.reverse! if options[:reverse]\n\n          # Go through each VM and yield it!\n          vms.each do |old_vm|\n            # We get a new VM from the environment here to avoid potentially\n            # stale VMs (if there was a config reload on the environment\n            # or something).\n            vm = @env.vms[old_vm.name]\n            yield vm\n          end\n        end\n\n        # This method will split the argv given into three parts: the\n        # flags to this command, the subcommand, and the flags to the","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/hashicorp/vagrant/blob/35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5/lib/vagrant/plugin/v1/command.rb#L88-L124","documentation":"The command declared single_target: true, more than one VM is in scope, and no primary VM is defined, so Vagrant cannot choose which VM to act on (lib/vagrant/plugin/v1/command.rb:106). It only fires when vms.length != 1 and @env.primary_vm is nil; the primary is designated with `config.vm.define :name, primary: true`.","triggerScenarios":"Running a single-target v1 command (ssh-style) with no name argument in a multi-machine Vagrantfile that lacks a primary: true machine — with_target_vms cannot disambiguate and raises.","commonSituations":"A Vagrantfile grew a second machine after scripts were written with no target name; the primary: true flag lost in a refactor; running interactive commands in a new multi-VM project for the first time.","solutions":["Pass the target explicitly: `vagrant <command> <machine-name>`","Mark exactly one machine as primary in the Vagrantfile: config.vm.define \"web\", primary: true","Reduce the environment to a single machine if multi-VM was unintended"],"exampleFix":"# before\nconfig.vm.define \"web\" do |web| ... end\nconfig.vm.define \"db\"  do |db|  ... end\n# `vagrant <single-target-cmd>` -> MultiVMTargetRequired\n\n# after\nconfig.vm.define \"web\", primary: true do |web| ... end\nconfig.vm.define \"db\"  do |db|  ... end","handlingStrategy":"validation","validationCode":"names = env.vms_ordered.map(&:name).map(&:to_s)\nabort \"multiple VMs (#{names.join(', ')}) and no primary; pass an explicit name\" if names.length > 1 && env.primary_vm.nil?","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always name the target machine explicitly in scripts that call single-target commands","Designate exactly one primary: true machine in every multi-machine Vagrantfile","Re-check single-target commands whenever a Vagrantfile gains a second machine"],"tags":["cli","vm-selection","multi-vm","v1-plugins"],"backgroundTag":"ambiguous-target-selection","analyzedSha":"35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5","analyzedAt":"2026-08-21T13:34:32.514Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}