Environment variable in user-data script
<p>I am having a problem with getting my user-data script to read an environment variable that gets set before the execution of the script. I am testing this using Vagrant.</p>

<p>So I have this line in my Vagrantfile...</p>

<pre><code>config.vm.provision "shell", path: "bin/vagrant/build.sh"
</code></pre>

<p>... that points to the provisioning script. The script contains everything necessary to load cloud-init, as outlined <a href="http://davemartorana.com/logs/software/cloud-init-in-vagrant-with-ubuntu-12-10-13-04/" rel="nofollow">here</a>.</p>

<p>Inside <code>build.sh</code>, I have a line...</p>

<pre><code>echo "SOME_PATH=/some/path" &gt;&gt; /etc/environment
</code></pre>

<p>... which presumably makes the environment variable available globally.</p>

<p>The full file, if you are interested:</p>

<pre><code>echo "SOME_PATH=/some/path" &gt;&gt; /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 &lt;&lt; 'END_OF_FILE_CONTENTS' &gt; /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
</code></pre>

<p>Now, I have a line that echoes <code>SOME_PATH</code> inside <code>/vagrant/bin/vagrant/user-data.sh</code> like this...</p>

<pre><code>#!/bin/bash

echo $SOME_PATH
</code></pre>

<p>... and when I run <code>vagrant up</code>, nothing gets printed! </p>

<p>Is there a way to make the environment variable available inside <code>user-data.sh</code>?</p>