使用 vagrant provisioner 创建 linux 环境变量 [英] Create linux environment variable using vagrant provisioner

查看:25
本文介绍了使用 vagrant provisioner 创建 linux 环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于开发目的,我让 vagrant 运行 Ubuntu.我使用了一个 shell 脚本配置器来下载/安装我的依赖项并创建一些别名,但是我在使用配置器创建环境变量(用于我的项目中的几个标志)方面遇到了障碍.最初我有类似的东西:

I've got vagrant running Ubuntu for development purposes. I've used a shell script provisioner to download/install my dependencies and create some aliases, but I've hit a wall in terms of using the provisioner to create environment variables (which are used for several flags within my project). Originally I had something like:

export MY_VAR='value'

进入我的配置器脚本,但后来发现你不能

Into my provisioner script, but then found out that you can't add environment variables from inside a shell script by running it normally. Fair enough, so I tried instead changing my line of the Vagrantfile to:

config.vm.provision "shell", inline: "source setup.sh"

这并没有解决问题.环境变量仍然不存在.我尝试将导出直接添加为内联:

Which didn't solve the problem. Environment variables still weren't there. I tried adding the exports directly as an inline:

config.vm.provision "shell", inline: "export MY_VAR='value'"

没有运气.当我 ssh 进入时仍然没有全局环境.有没有办法使用 shell 脚本来设置 bash 环境变量,或者是时候放弃 shell 配置程序并学习厨师了?

No luck. Still no global environment when I ssh'ed in. Is there a way to use the shell script to set a bash environment variable, or is it time to throw in the towel on shell provisioners and learn chef?

推荐答案

您应该让配置脚本在您的 .profile 中添加一行:

You should have the provisioning script add a line to your .profile:

echo "export VAR=value" >> ~/.profile

在登录时,.profile中脚本将被通过bash的读取和变量将被设置.

On login, the .profile script will be read by bash and the variable will be set.

这篇关于使用 vagrant provisioner 创建 linux 环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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