2013-10-21 41 views
0

我有一个非常简单的Vagrantfile。基本上,这是用了很多的东西删除,超级容易直列壳供应者默认文件:Vagrant何时运行配置程序?

Vagrant.configure("2") do |config| 
    config.vm.define "test" do |test| 
    test.vm.box = "precise64" 
    test.vm.box_url = "http://files.vagrantup.com/precise64.box" 

    test.vm.network :forwarded_port, guest: 3000, host: 3000 

    test.vm.network :private_network, ip: "192.168.33.100" 

    test.vm.provider :virtualbox do |vb| 
     vb.customize [ "modifyvm", :id, "--cpus", 2 ] 
     vb.customize [ "modifyvm", :id, "--memory", 1024 ] 
    end 

    test.vm.provision :shell, :inline => "echo \"Hello world!\"" 
    end 
end 

当我运行vagrant up首次,本机被创建,引导和外壳供应方是按预期运行:控制台上的最后一行显示为Hello world!

现在,如果我第二次运行vagrant haltvagrant up,机器启动,但不运行配置器。至少没有消息打印出来给终端。

在我看来,这是相对于该条规定,Vagrant documentation

供应方的三种情况运行:vagrant upvagrant reloadvagrant provision

为什么脚本不能运行?

回答

2

我不确定这是否发生了变化,但对于shell脚本,您还可以使用run: "always"标志来确保shell脚本得到执行at all times

Vagrant.configure("2") do |config| 
    config.vm.provision "shell", inline: "echo hello", 
    run: "always" 
end