问题
I'm creating a Red Hat Enterprise Linux 7 VM in VirtualBox with vagrant. If I have a base box that both doesn't have the VirtualBox guest additions, and isn't registered, then I'd manually need to do the following:
- Register the box with subscription-manager
- Install guest additions
The reason that I'd need to perform registration first, is that to install guest additions, I'd need to install some extra packages.
Now, there are 3rd-party vagrant plugins for both of these tasks: vagrant-registration and vagrant-vbguest.
The issue that I'm having is that the vagrant-vbguest
plugin will always try to run first, and will fail to download the packages that it needs, because the vagrant-registration
plugin hasn't yet had a chance to register the system.
Is there a way to force one of them to be run before the other? Or any other alternative solution that I haven't thought of yet (I'm not a vagrant wizard (or is that just called a vagrant?) yet)?
回答1:
in the spirit of my comments but it should be in a more automatic way
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
not sure though that it will run in the correct order (did not try myself)
Edit the issue with this code is that it will try to run the vbguest right when the command is launched so before the vm is running so vbguest cannot install the necessary libs.
the other possibility I see is to use the vagrant trigger plugin (https://github.com/emyl/vagrant-triggers), you can define to run specific script after specific command has been run
config.vbguest.auto_update = false
config.trigger.after :up do
run "vagrant vbguest --auto-reboot --no-provision"
end
the vbguest is correctly run after the machine is booted (so I am assuming after vagrant-registration did its own stuff)
the output (interesting part) of running 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.
installation of the guest additions goes on and machine rebooted ok
回答2:
This seems to be an issue with vagrant-registration plugin. See https://github.com/projectatomic/adb-vagrant-registration/issues/69
The issue has been fixed and the fixed version is released now i.e. https://rubygems.org/gems/vagrant-registration/versions/1.2.2
来源:https://stackoverflow.com/questions/31610801/how-can-i-define-the-run-order-of-vagrant-middleware-plugins