对于 Vagrant,我的目标是在我的 Ubuntu 主机上拥有三台主机器和两台节点机器。
我的Vagrantfile
:
Vagrant.configure("2") do |config|
config.ssh.insert_key = false
(1..3).each do |i|
config.vm.define "master" do |master|
master.vm.box = "ubuntu/bionic64"
end
end
(1..2).each do |i|
config.vm.define "node" do |node|
node.vm.box = "ubuntu/bionic64"
end
end
config.vm.network "public_network"
config.vm.provider "virtualbox" do |vb|
vb.memory = "3072"
vb.cpus = "3"
end
end
我之后vagrant up
:
$ vagrant status
Current machine states:
master running (virtualbox)
node running (virtualbox)
为什么循环失败?
答案1
-#{i}
两个循环中都丢失了do
,而其他一切都很好,不需要进一步的更改:
Vagrant.configure("2") do |config|
config.ssh.insert_key = false
(1..3).each do |i|
config.vm.define "master-#{i}" do |master|
master.vm.box = "ubuntu/bionic64"
end
end
(1..2).each do |i|
config.vm.define "node-#{i}" do |node|
node.vm.box = "ubuntu/bionic64"
end
end
config.vm.network "public_network"
config.vm.provider "virtualbox" do |vb|
vb.memory = "3072"
vb.cpus = "3"
end
end