问题
In my Vagrantfile, I have two shell provisions: one is for installing system dependencies for my project, and another is for starting up nginx server.
So what I wanted to have is when I vagrant reload --provision
, can I ignore the provision for installing the system dependencies, and just start up the nginx server instead?
Sample code:
VAGRANTFILE_API_VERSION = '2'
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
...
# Ignore this line on VM reload
config.vm.provision 'shell', path: 'provision/install.sh'
# Execute this one only on VM reload
config.vm.provision 'shell', path: 'provision/start_nginx.sh'
...
end
回答1:
One simple solution, but a little bit hack method is
You can pass environment variables while running vagrant reload command like this
RELOAD=true vagrant reload --provision
then in VagrantFile
VAGRANTFILE_API_VERSION = '2'
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
...
# Ignore this line on VM reload
if (ENV['RELOAD'] != true)
config.vm.provision 'shell', path: 'provision/install.sh'
end
# Execute this one only on VM reload
config.vm.provision 'shell', path: 'provision/start_nginx.sh'
...
end
来源:https://stackoverflow.com/questions/27221619/when-i-do-a-vagrant-provisioning-can-i-ignore-some-provision-codes-from-vagrant