0
我遇到了讓我的用戶數據腳本讀取腳本執行前設置的環境變量的問題。我正在測試這個使用流浪漢。用戶數據腳本中的環境變量
所以我此行中我Vagrantfile ...
config.vm.provision "shell", path: "bin/vagrant/build.sh"
...指向配置腳本。該腳本包含加載cloud-init所需的所有內容,如here所述。
裏面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
現在,我有一個呼應SOME_PATH
內/vagrant/bin/vagrant/user-data.sh
這樣一行...
#!/bin/bash
echo $SOME_PATH
...當我運行vagrant up
,沒有打印!
有沒有辦法讓user-data.sh
內的環境變量可用?