将环境变量传递给 vagrant shell 配置器 [英] Pass environment variables to vagrant shell provisioner

查看:32
本文介绍了将环境变量传递给 vagrant shell 配置器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您使用的是 Ruby 配置器,调用 vagrant up 时传递环境变量看起来很简单:

It looks like passing environment variables when calling vagrant up is simple if you're using a Ruby provisioner:

VAR=123 vagrant up

在 Vagrantfile 中:

In the Vagrantfile:

ENV['VAR']

我如何使用 :shell 供应商做到这一点?简单地这样做似乎不起作用:

How do I do this with the :shell provisioner? Simply doing this does not seem to work:

$VAR

推荐答案

这并不理想,但我现在可以使用:

It's not ideal, but I got this to work for now:

config.vm.provision "shell" do |s|
    s.inline = "VAR1 is $1 and VAR2 is $2"
    s.args   = "#{ENV['VAR1']} #{ENV['VAR2']}"
end

这篇关于将环境变量传递给 vagrant shell 配置器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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