我有下面的流浪文件,它指定了两台机器——前端和后端。
Vagrant.configure(2) do |config|
config.vm.box = "frontend"
config.vm.network "private_network", ip: "192.168.0.5"
config.vm.provider "virtualbox" do |vb|
vb.gui = true
vb.memory = "4096"
end
config.vm.communicator = "winrm"
config.vm.provision "shell", path: "Provision.ps1"
config.vm.define "db" do |db|
db.vm.box = "backend"
db.vm.network "private_network", ip: "192.168.0.10"
db.vm.provider "virtualbox" do |vb|
vb.gui = true
vb.memory = "4096"
end
db.vm.communicator = "winrm"
db.vm.provision "shell", path: "ProvisionRemote.ps1"
end
end
根据Multi-Machine文档,当我键入流浪者时,它应该首先启动前端箱并运行Provision.ps1,然后启动后端箱并在其上运行ProvisionRemote.ps1(out-of-in-)。
然而,实际情况是,后端箱首先启动,然后尝试在其上运行Provision.ps1(用于前端箱)。
Bringing machine 'db' up with 'virtualbox' provider...
==> db: Importing base box 'backend'...
==> db: Matching MAC address for NAT networking...
==> db: Checking if box 'backend' is up to date...
==> db: Setting the name of the VM: RemoteBox_db_1459513634410_78500
==> db: Clearing any previously set network interfaces...
==> db: Preparing network interfaces based on configuration...
db: Adapter 1: nat
db: Adapter 2: hostonly
db: Adapter 3: hostonly
==> db: Forwarding ports...
db: 5985 => 55985 (adapter 1)
db: 5986 => 55986 (adapter 1)
==> db: Running 'pre-boot' VM customizations...
==> db: Booting VM...
==> db: Waiting for machine to boot. This may take a few minutes...
db: WinRM address: 127.0.0.1:55985
db: WinRM username: vagrant
db: WinRM transport: plaintext
==> db: Machine booted and ready!
==> db: Checking for guest additions in VM...
db: The guest additions on this VM do not match the installed version of
db: VirtualBox! In most cases this is fine, but in rare cases it can
db: prevent things such as shared folders from working properly. If you see
db: shared folder errors, please make sure the guest additions within the
db: virtual machine match the version of VirtualBox you have installed on
db: your host and reload your VM.
db:
db: Guest Additions Version: 4.3.28
db: VirtualBox Version: 5.0
==> db: Configuring and enabling network interfaces...
==> db: Mounting shared folders...
db: /vagrant => E:/_workingSource/project/env/
==> db: Running provisioner: shell...
db: Running: Provision.ps1 as c:tmpvagrant-shell.ps1
它为什么要这么做?我做错了什么?
您应该强调您有两台机器
在这里,你只定义了一台机器(config和你确实覆盖了后端块中定义的一些参数,但这实际上是同一台机器的定义),所以流浪者正在引导你定义的一台机器,并试图运行所有的provisioner
以下工作并定义了2台机器
Vagrant.configure(2) do |config|
config.vm.communicator = "winrm"
config.vm.define "front" do |front|
front.vm.box = "frontend"
front.vm.network "private_network", ip: "192.168.0.5"
front.vm.provider "virtualbox" do |vb|
vb.gui = true
vb.memory = "4096"
end
front.vm.provision "shell", path: "Provision.ps1"
end
config.vm.define "db" do |db|
db.vm.box = "backend"
db.vm.network "private_network", ip: "192.168.0.10"
db.vm.provider "virtualbox" do |vb|
vb.gui = true
vb.memory = "4096"
end
db.vm.provision "shell", path: "ProvisionRemote.ps1"
end
end
config*参数适用于2台机器(如config.vm.communicator
),因此所有通用参数都应应用于config.
变量(注意:我没有尝试将虚拟盒提供程序置于config下,但只要它相同,它就应该工作),如果您需要特定于机器的参数,则必须在特定块(如定义为front.vm.network "private_network", ip: "192.168.0.5"
的IP)中定义
这种方法按正确的顺序激发提供者。。。
config.vm.provision "docker" do |d|
# installs docker
end
config.vm.provision :shell do |sh|
sh.privileged = false
sh.inline = $provision
end
config.vm.provision :shell do |sh|
sh.privileged = false
sh.path = "generateWebserverInstallEnvironment.sh"
end