{"record":{"id":"9bd8427923b24847","repo":"hashicorp/vagrant","slug":"could-not-run-remote-script-on-machine-name-bec","errorCode":null,"errorMessage":"Could not run remote script on %{machine_name} because its state is %{state}","messagePattern":"Could not run remote script on %(.+?) because its state is %(.+?)","errorType":"exception","errorClass":"Vagrant::Errors::TriggersGuestNotRunning","httpStatus":null,"severity":"error","filePath":"lib/vagrant/plugin/v2/trigger.rb","lineNumber":312,"sourceCode":"          end\n        end\n\n        # Runs a script on the guest\n        #\n        # @param [ShellProvisioner/Config] config A Shell provisioner config\n        def run_remote(config, on_error, exit_codes)\n          if !@machine\n            # machine doesn't even exist.\n            if on_error == :halt\n              raise Errors::TriggersGuestNotExist\n            else\n              @ui.warn(I18n.t(\"vagrant.errors.triggers_guest_not_exist\"))\n              @ui.warn(I18n.t(\"vagrant.trigger.on_error_continue\"))\n              return\n            end\n          elsif @machine.state.id != :running\n            if on_error == :halt\n              raise Errors::TriggersGuestNotRunning,\n                machine_name: @machine.name,\n                state: @machine.state.id\n            else\n              @machine.ui.error(I18n.t(\"vagrant.errors.triggers_guest_not_running\",\n                                        machine_name: @machine.name,\n                                        state: @machine.state.id))\n              @machine.ui.warn(I18n.t(\"vagrant.trigger.on_error_continue\"))\n              return\n            end\n          end\n\n          prov = VagrantPlugins::Shell::Provisioner.new(@machine, config)\n\n          begin\n            prov.provision\n          rescue => e\n            @machine.ui.error(I18n.t(\"vagrant.errors.triggers_run_fail\"))\n","sourceCodeStart":294,"sourceCodeEnd":330,"githubUrl":"https://github.com/hashicorp/vagrant/blob/35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5/lib/vagrant/plugin/v2/trigger.rb#L294-L330","documentation":"A `run_remote` trigger (executes inside the guest) fired while the target machine's state was not :running (lib/vagrant/plugin/v2/trigger.rb:312). This path means the machine object exists but is in another state (:poweroff, :suspended, etc.); a machine that does not exist at all raises TriggersGuestNotExist instead. With on_error :halt the error is raised; otherwise Vagrant warns and continues.","triggerScenarios":"A Vagrantfile like `trigger.after :halt do |t| t.run_remote = {inline: \"...\"} end` — after halting, the state is :poweroff so the remote script cannot run; similarly after :suspend, or an :up trigger firing in a flow where the guest is not yet running.","commonSituations":"Copy-pasted trigger blocks attached to the wrong command/stage; expecting run_remote to work during teardown; the guest crashing or being halted externally before the trigger fires.","solutions":["Move the run_remote trigger to a stage where the guest is guaranteed running: trigger.before :halt, or trigger.after :up / after :provision","Use host-side `t.run` instead of `t.run_remote` for teardown stages (after halt/destroy)","Set t.on_error = :continue if the trigger is opportunistic and failure is tolerable","Verify current state with `vagrant status <machine>` before re-running"],"exampleFix":"# before\ntrigger.after :halt do |t|\n  t.run_remote = { inline: \"echo bye\" }  # guest is powered off here\nend\n\n# after\ntrigger.before :halt do |t|\n  t.run_remote = { inline: \"echo bye\" }  # guest still running\nend","handlingStrategy":"validation","validationCode":"machine = env.machine(:web, :virtualbox)\nabort \"guest not running (state: #{machine.state.id})\" unless machine.state.id == :running","typeGuard":null,"tryCatchPattern":"begin\n  env.cli(:halt)\nrescue Vagrant::Errors::TriggersGuestNotRunning => e\n  d = e.extra_data # {machine_name:, state:}\n  warn \"#{d[:machine_name]} was #{d[:state]} — move the run_remote trigger to a stage where the guest runs\"\nend","preventionTips":["Pair run_remote only with commands that leave the guest running (after :up, before :halt, after :provision)","Use host-side `run` for teardown stages (after halt/destroy)","Smoke-test each trigger stage against `vagrant status` before committing the Vagrantfile"],"tags":["triggers","guest-state","run-remote","machine-state"],"backgroundTag":"machine-not-running","analyzedSha":"35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5","analyzedAt":"2026-08-21T13:34:32.514Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}