1

我想在配置期间使环境变量对 Vagrant 可用,以便我可以运行一些依赖它们获取凭据的命令。具体aws clipg_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
4

1 回答 1

1

您以rootbash 为vagrant用户的用户身份运行配置,因此请确保通过添加以 vagrant 身份运行配置privileged: false

config.vm.provision :shell, privileged: false, 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
于 2016-06-04T09:31:42.060 回答