流氓文件中的Shell环境变量只能首先传递 [英] Shell environment variables in vagrant files are only passed on first up

查看:207
本文介绍了流氓文件中的Shell环境变量只能首先传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行Vagrant 1.8.5,它支持 Vagrantfile中的环境变量在配置时使用这样的格式


config.vm.provision:shell,path:bootstrap.sh env:
{MYSQL_DB_USERNAME=>django,
MYSQL_DB_PASSWORD=>supersecretpasswordwasreplaced}


然而,当我在没有配置的情况下,当我执行 up ,或者当SSH进入服务器来做任务时,我也希望这些环境变量也可用。我可以找到的明显的方法是将它们内置到框中(似乎过度杀伤),或者

$ b <

  • 重复他们在我的 config.ssh。 forward_env ,以便它们可供供应商和SSH使用。



  • 有更好的方法吗?

    解决方案>

    我不知道最好的最终方式 - 我看到这个问题不时出现和讨论。


    在我的config.ssh.forward_env中重复它们,以便它们可供供应商和SSH使用。


    好吧,这听起来像一个很好的解决方案,但有一些缺点,我已经讨论了在这问题已经



    个人当我需要设置env变量时,我将它们添加到 .profile file:

      config.vm.provisionshell,privileged:false,inline:<< -SHELL 
    echoexport MYSQL_DB_USERNAME = django> /home/vagrant/.profile
    echoexport MYSQL_DB_PASSWORD = supersecretpasswordwasreplaced> /home/vagrant/.profile
    SHELL

    当您登录时,他们将可用


    I'm running Vagrant 1.8.5, which supports environment variables in the Vagrantfile at provisioning time using a format like this

    config.vm.provision :shell, path: "bootstrap.sh", env: {"MYSQL_DB_USERNAME"=>"django", "MYSQL_DB_PASSWORD"=>"supersecretpasswordwasreplaced"}

    However, I would like these environment variables to also be available when I do up without provisioning, or when I SSH into the server to do jobs. The obvious ways I can find are

    • to have them built into the box (seems like overkill) or
    • repeat them in my config.ssh.forward_env so that they are available to both the provisioner and SSH.

    Is there a better way?

    解决方案

    I am not sure about the best ultimate way - I've seen this question popping from time to time and discussion.

    repeat them in my config.ssh.forward_env so that they are available to both the provisioner and SSH.

    well, it could sound like a good solution but there's some drawback, I've discussed in this question already

    Personally when I need to set env variable, I would add them in the .profile file:

      config.vm.provision "shell", privileged: false, inline: <<-SHELL
        echo "export MYSQL_DB_USERNAME = django" > /home/vagrant/.profile
        echo "export MYSQL_DB_PASSWORD = supersecretpasswordwasreplaced" > /home/vagrant/.profile
      SHELL
    

    They will be available when you login.

    这篇关于流氓文件中的Shell环境变量只能首先传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆