我想在配置期间使环境变量对 Vagrant 可用,以便我可以运行一些依赖它们获取凭据的命令。具体aws cli和pg_restore。
例如,pg_restore需要访问我在.bash_profile. 我尝试运行source /home/vagrant/.bash_profile导出所需的 AWS 环境变量,但稍后在我的配置块中,该aws命令失败,因为未设置环境变量。
.bash_profile
export AWS_ACCESS_KEY_ID='keyid'
export AWS_SECRET_ACCESS_KEY='secret'
Vagrantfile 配置块
config.vm.provision :shell, run: "always", inline: <<-SH.gsub(/^\s*/,"")
source /home/vagrant/.bash_profile
aws s3 cp s3://bucket/sql/file /tmp/file # fail, missing credentials
echo $(printenv | grep AWS_) # outputs blank line
SH