Vagrant: config.trigger.after :provision doesn't appear to run

Created on 16 May 2018  ยท  3Comments  ยท  Source: hashicorp/vagrant

Please note that the Vagrant issue tracker is reserved for bug reports and
enhancements. For general usage questions, please use the Vagrant mailing list:
https://groups.google.com/forum/#!forum/vagrant-up. Thank you!

Vagrant version

2.1.1

Host operating system

Windows 10

Guest operating system

Amazon Linux

Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.ssh.insert_key = false

  # ssite
  config.vm.define "site" do |site|
    site.vm.box = "winky/amazonlinux-2"
    site.vm.hostname ="site"
    site.vm.network "private_network", ip: "192.168.51.11"
    site.vm.synced_folder "src/", "/srv/www/site", type: "virtualbox", create: true, group: "ec2-user", owner: "ec2-user"

    site.vm.provider "virtualbox" do |vb|
      vb.name = "site"
      vb.customize ["modifyvm", :id, "--memory", "512"]
      vb.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"]
    end

    site.vm.provision "shell" do |s|
      s.path = "scripts/provision.sh"
    end
  end

  config.trigger.after :provision do |trigger|
    trigger.run_remote = {inline: "cd /vagrant && sudo npm run debug"}
  end
end

Debug output

https://gist.github.com/Renari/07358cd52394b5e2f6cd80d26d66d030

Expected behavior

What should have happened?
cd /vagrant && sudo npm run debug should have run at the end of the provision, thus starting the application.

Actual behavior

What actually happened?
The application did not start, requiring me to ssh into the machine and start it myself.

Steps to reproduce

  1. Create a new machine using vagrant up
bug triggers

Most helpful comment

Oh wait @Renari - apologies. I believe this is a misunderstanding for what the trigger command key is about. This works, however it's expected to run _after_ the provision command, not the provision step in vagrant up. If you run vagrant provision, you'll see that your defined trigger runs after. If you simply want that command to run after your machine has been brought up, then the trigger should be config.trigger.after :up. Thanks!

We are planning on supporting triggers that can be injected in the Vagrant lifecycle, but for the moment the command keys expected are around specified commands.

All 3 comments

Hi @Renari - this looks like a bug to me. I've labeled it as such and dropped it into our next milestone to be fixed. Thanks for reporting the issue!

Oh wait @Renari - apologies. I believe this is a misunderstanding for what the trigger command key is about. This works, however it's expected to run _after_ the provision command, not the provision step in vagrant up. If you run vagrant provision, you'll see that your defined trigger runs after. If you simply want that command to run after your machine has been brought up, then the trigger should be config.trigger.after :up. Thanks!

We are planning on supporting triggers that can be injected in the Vagrant lifecycle, but for the moment the command keys expected are around specified commands.

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jsirex picture jsirex  ยท  3Comments

DreadPirateShawn picture DreadPirateShawn  ยท  3Comments

hesco picture hesco  ยท  3Comments

OtezVikentiy picture OtezVikentiy  ยท  3Comments

Cbeck527 picture Cbeck527  ยท  3Comments