当我执行vagrant设置时,我可以忽略vagrant重新加载时vagrant文件中的一些设置代码吗?
在我的文件中,我有两个shell配置:一个用于为我的项目安装系统依赖项,另一个用于启动nginx服务器 所以我想要的是,当我当我执行vagrant设置时,我可以忽略vagrant重新加载时vagrant文件中的一些设置代码吗?,vagrant,vagrantfile,Vagrant,Vagrantfile,在我的文件中,我有两个shell配置:一个用于为我的项目安装系统依赖项,另一个用于启动nginx服务器 所以我想要的是,当我vagrant reload--provision时,我可以忽略安装系统依赖项的规定,而只启动nginx服务器吗 示例代码: VAGRANTFILE_API_VERSION = '2' Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| ... # Ignore this line on VM
vagrant reload--provision
时,我可以忽略安装系统依赖项的规定,而只启动nginx服务器吗
示例代码:
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
一个简单的解决方案,但有一点黑客的方法是 您可以在像这样运行vagrant reload命令时传递环境变量
RELOAD=true vagrant reload --provision
然后在vagrant文件中
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