本着我评论的精神,但应该以更自动的方式
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vbguest.auto_update = false
if Vagrant.has_plugin?("vagrant-registration")
system "vagrant vbguest --auto-reboot --no-provision" if ARGV[0] == 'up'
end
不确定它是否会以正确的顺序运行(我自己没有尝试)
编辑此代码的问题是它会在命令启动时尝试运行 vbguest,因此在 vm 运行之前,因此 vbguest 无法安装必要的库。
我看到的另一种可能性是使用 vagrant 触发器插件(https://github.com/emyl/vagrant-triggers),您可以定义在运行特定命令后运行特定脚本
config.vbguest.auto_update = false
config.trigger.after :up do
run "vagrant vbguest --auto-reboot --no-provision"
end
vbguest 在机器启动后正确运行(所以我假设在 vagrant-registration 做了自己的事情之后)
运行的输出(有趣的部分)vagrant up
:
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
default: The guest additions on this VM do not match the installed version of
default: VirtualBox! In most cases this is fine, but in rare cases it can
default: prevent things such as shared folders from working properly. If you see
default: shared folder errors, please make sure the guest additions within the
default: virtual machine match the version of VirtualBox you have installed on
default: your host and reload your VM.
default:
default: Guest Additions Version: 4.2.0
default: VirtualBox Version: 4.3
==> default: Mounting shared folders...
default: /vagrant => /Users/fhenri/project/examples/vagrant/precise
==> default: Running triggers after up...
==> default: Executing command "vagrant vbguest --auto-reboot --no-provision"...
==> default: GuestAdditions versions on your host (4.3.16) and guest (4.2.0) do not match.
来宾添加的安装继续进行,机器重新启动正常