问题描述
限时送ChatGPT账号..在我的 Vagrantfile 中,我有两个 shell 配置:一个用于为我的项目安装系统依赖项,另一个用于启动 nginx 服务器.
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.
那么我想要的是当我vagrant reload --provision
时,我可以忽略安装系统依赖项的规定,而只是启动nginx服务器吗?
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?
示例代码:
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
推荐答案
一个简单的解决方案,但有点hack方法是
One simple solution, but a little bit hack method is
你可以像这样在运行 vagrant reload 命令时传递环境变量
You can pass environment variables while running vagrant reload command like this
RELOAD=true vagrant reload --provision
然后在 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
这篇关于当我进行 vagrant 配置时,我可以在 vagrant 重新加载时忽略 Vagrantfile 中的一些配置代码吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论