私のユーザーデータスクリプトがスクリプトの実行前に設定されている環境変数を読み込むのに問題があります。私はバゲントを使ってこれをテストしています。プロビジョニング・スクリプトを指すユーザーデータスクリプト内の環境変数
だから私は私のVagrantfileにこのラインを持っている...
config.vm.provision "shell", path: "bin/vagrant/build.sh"
...。スクリプトには、hereのように、クラウド-initをロードするために必要なものがすべて含まれています。おそらく世界的に環境変数を利用できるように
build.sh
インサイド
、私はラインを持っている...
echo "SOME_PATH=/some/path" >> /etc/environment
...。
完全なファイル、あなたが興味を持っている場合:今
echo "SOME_PATH=/some/path" >> /etc/environment
# Check to see if we have done this already.
if [ -f /.vagrant_build_done ]; then
echo "Found, not running."
exit
fi
# Make the box think it hasn't init-ed yet.
rm -rf /var/lib/cloud/instance/*
rm -rf /var/lib/cloud/seed/nocloud-net/user-data
# Seed our own init scripts
cat << 'END_OF_FILE_CONTENTS' > /var/lib/cloud/seed/nocloud-net/user-data
Content-Type: multipart/mixed; boundary="===============apiserversStackMultipartMessage=="
MIME-Version: 1.0
# Beginning of our user-data script.
--===============apiserversStackMultipartMessage==
#include
/vagrant/bin/vagrant/user-data.sh
--===============apiserversStackMultipartMessage==--
END_OF_FILE_CONTENTS
# End of our user-data script.
# Re-run cloud-init.
cloud-init init
cloud-init modules --mode init
cloud-init modules --mode config
cloud-init modules --mode final
# Do not let this run again.
touch /.vagrant_build_done
、私は...このような/vagrant/bin/vagrant/user-data.sh
内部SOME_PATH
をエコーラインを持っている
#!/bin/bash
echo $SOME_PATH
...と私が実行したときvagrant up
、何も印刷されません!
user-data.sh
の中で環境変数を使用できるようにする方法はありますか?