且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将环境变量传递给流氓外壳提供程序

更新时间:2022-10-31 08:05:51

这不太理想,但我现在可以这样工作:

  config.vm.provisionshelldo | s | 
s.inline =VAR1为$ 1,VAR2为$ 2
s.args =#{ENV ['VAR1']}#{ENV ['VAR2']}
end


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

VAR=123 vagrant up

In the Vagrantfile:

ENV['VAR']

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