How to pass Windows host env into Vagrantfile?

杀马特。学长 韩版系。学妹 提交于 2019-12-25 09:17:05

问题


I have a Windows-7 host running Vagrant (1.9.1), from which I start a CentOS guest VM

I want to pass a Windows environment variable into the guest via the Vagrantfile.

Let's call the environment variable ABC

>echo %ABC% 123

I know I can pass static values in as:

config.vm.provision :shell, path: "scripts/bootstrap.sh", env: {"MYVAR" => "123"}

But I don't know how to translate the env var - this doesn't work (passes literal: %ABC%):

config.vm.provision :shell, path: "scripts/bootstrap.sh", env: {"MYVAR" => "%ABC%"}

Any help appreciated


回答1:


Cardboard programmer strikes again...

Three minutes after asking the question I found the answer (and I'd already spent three hours looking before I asked)

config.vm.provision :shell, path: "scripts/bootstrap.sh", env: {"MYVAR" => ENV['ABC']}

tada!



来源:https://stackoverflow.com/questions/42249989/how-to-pass-windows-host-env-into-vagrantfile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!