当我进行 vagrant 配置时,我可以在 vagrant 重新加载时忽略 Vagrantfile 中的一些配置代码吗?

编程入门 行业动态 更新时间:2024-10-26 17:27:26
本文介绍了当我进行 vagrant 配置时,我可以在 vagrant 重新加载时忽略 Vagrantfile 中的一些配置代码吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-04-28 07:43:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1169730.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:当我   加载   代码   vagrant   Vagrantfile

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!