我有以下vagrantfile,它指定了2台机器 - 前端和后端框。
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
当我输入vagrant时,根据Multi-Machine文档,它应首先启动前端框并运行Provision.ps1,然后启动后端框并在其上运行ProvisionRemote.ps1(外部)。
然而,发生的事情是后端框首先启动,然后它尝试在其上运行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:\tmp\vagrant-shell.ps1
为什么这样做?我做错了什么?
答案 0 :(得分:4)
你应该强调你有2台机器
在这里你只需要定义一台机器(配置并且你确实覆盖了后端块中定义的一些参数,但这实际上是相同的机器定义)所以vagrant正在启动您定义的一台机器并尝试运行所有配置器
以下工作并定义了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.
变量(注意:我没有尝试放置虚拟框提供程序)在配置下,但它应该工作,只要它是相同的),如果你需要机器特定的参数,你必须在特定的块内定义(如IP定义为front.vm.network "private_network", ip: "192.168.0.5"
)
答案 1 :(得分:0)
这种方法以正确的顺序激发供应商......
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