{"record":{"id":"6c05bcc11e93e152","repo":"hashicorp/vagrant","slug":"this-command-requires-a-specific-vm-name-to-target-6c05bc","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/v2/command.rb","lineNumber":226,"sourceCode":"                raise Errors::VMNotFoundError, name: name if !machines[0]\n              end\n            end\n          else\n            # No name was given, so we return every VM in the order\n            # configured.\n            @logger.debug(\"Loading all machines...\")\n            machines = @env.machine_names.map do |machine_name|\n              get_machine.call(machine_name)\n            end\n          end\n\n          @logger.debug(\"have machine list to process\")\n\n          # Make sure we're only working with one VM if single target\n          if options[:single_target] && machines.length != 1\n            @logger.debug(\"Using primary machine since single target\")\n            primary_name = @env.primary_machine_name\n            raise Errors::MultiVMTargetRequired if !primary_name\n            machines = [get_machine.call(primary_name)]\n          end\n\n          # If we asked for reversed ordering, then reverse it\n          machines.reverse! if options[:reverse]\n\n          # Go through each VM and yield it!\n          color_order = [:default]\n          color_index = 0\n\n          machines.each do |machine|\n            if (machine.state && machine.state.id != :not_created &&\n                !machine.index_uuid.nil? && !@env.machine_index.include?(machine.index_uuid))\n              machine.recover_machine(machine.state.id)\n            end\n\n            # Set the machine color\n            machine.ui.opts[:color] = color_order[color_index % color_order.length]","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/hashicorp/vagrant/blob/35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5/lib/vagrant/plugin/v2/command.rb#L208-L244","documentation":"A single-target v2 command (options[:single_target]) ended up with multiple machines in scope and no primary_machine_name, so Vagrant cannot pick one (lib/vagrant/plugin/v2/command.rb:226). The primary is designated with `config.vm.define :name, primary: true`; without it, commands like `vagrant ssh` with no argument cannot proceed in multi-machine projects.","triggerScenarios":"`vagrant ssh` (or any single-target command) with no machine argument in a Vagrantfile defining several machines where none carries primary: true.","commonSituations":"A second machine added to the Vagrantfile after single-target workflows were scripted; primary: true lost in a refactor; new teammates cloning a multi-VM project for the first time.","solutions":["Pass the machine name explicitly: `vagrant ssh web`","Designate a primary machine: config.vm.define \"web\", primary: true","Remove the extra machine definition if multi-VM was unintentional"],"exampleFix":"# before\nconfig.vm.define \"web\" do |web| ... end\nconfig.vm.define \"db\"  do |db|  ... end\n# `vagrant ssh` -> 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.machine_names.map(&:to_s)\nabort \"multiple machines (#{names.join(', ')}) and no primary defined — pass a name\" if names.length > 1 && env.primary_machine_name.nil?","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass an explicit machine name to single-target commands in scripts","Mark one machine primary: true in every multi-machine Vagrantfile","Review triggers/hooks that call single-target commands when adding machines"],"tags":["cli","machine-selection","multi-vm","v2-plugins"],"backgroundTag":"ambiguous-target-selection","analyzedSha":"35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5","analyzedAt":"2026-08-21T13:34:32.514Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}