Vagrant配置错误 - “必须指定一个框”。

时间:2017-03-06 16:49:48

标签: vagrant vagrantfile

我的配置如下,方框工作正常:

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

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|

  (1..4).each do |i|

    config.vm.define "node#{i}", autostart:true do |node|

        config.vm.box = "ubuntu/trusty64"
        config.vm.hostname="node#{i}"
        config.vm.network "private_network", ip: "192.168.59.#{i}"
        config.vm.synced_folder "~/Documents/csunp/unp", "/vagrant/unp"
        config.vm.provider "virtualbox" do |v|
            v.name = "node#{i}"
            v.memory = 512
            v.cpus = 1
        end
    end
  end
end

但是一旦我打开电脑,我就不能再回去了。 运行vagrant up,我收到以下错误:

Bringing machine 'node1' up with 'virtualbox' provider...
Bringing machine 'node2' up with 'virtualbox' provider...
Bringing machine 'node3' up with 'virtualbox' provider...
Bringing machine 'node4' up with 'virtualbox' provider...
There are errors in the configuration of this machine. Please fix
the following errors and try again:

vm:
* A box must be specified.

这有什么问题?提前谢谢。

1 个答案:

答案 0 :(得分:1)

哼哼你的Vagrantfile编写得不是很好,你创建了一个循环来创建4个带有节点变量但仍然使用config.vm的实例

如果您想保持简单,请转到

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

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|

  (1..4).each do |i|

    config.vm.define "node#{i}", autostart:true do |node|

        node.vm.box = "ubuntu/trusty64"
        node.vm.hostname="node#{i}"
        node.vm.network "private_network", ip: "192.168.59.#{i}"
        node.vm.synced_folder "~/Documents/csunp/unp", "/vagrant/unp"
        node.vm.provider "virtualbox" do |v|
            v.name = "node#{i}"
            v.memory = 512
            v.cpus = 1
        end
    end
  end
end

如果您为所有4个VM使用相同的框,则可以写为

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

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|

  config.vm.box = "ubuntu/trusty64"
  config.vm.synced_folder "~/Documents/csunp/unp", "/vagrant/unp"

  (1..4).each do |i|

    config.vm.define "node#{i}", autostart:true do |node|

        node.vm.hostname="node#{i}"
        node.vm.network "private_network", ip: "192.168.59.#{i}"
        node.vm.provider "virtualbox" do |v|
            v.name = "node#{i}"
            v.memory = 512
            v.cpus = 1
        end
    end
  end
end
相关问题