fabfile doesn't see remote environment variables
<p>My remote server (192.168.3.68) contains several environment variables set in my ~/.bashrc:</p>

<pre><code># For instance
export MY_DATABASE_HOST=127.0.0.1
</code></pre>

<p>When I put <code>run('echo $MY_DATABASE_HOST')</code> in <code>fabfile.py</code>, it shows:</p>

<pre><code>[192.168.3.68] run: echo $MY_DATABASE_HOST
[192.168.3.68] output:

Done
Disconnecting from 192.168.3.68... done.
</code></pre>

<p>I've tried adding <code>run('source ~/.bashrc')</code> immediately before the echo but nothing changes.</p>

<p>Why isn't the set environment variables in ~/.bashrc visible to fabfile?</p>

<p>What do I do to fix that because fabfile must be able to read these variables?</p>

<p><strong>UPDATE</strong></p>

<pre><code>from fabric.context_managers import prefix

# This didn't work
with prefix('source /home/meandme/.bashrc'):
    run('echo $MY_DATABASE_HOST')
# This didn't work either
run('source /home/meandme/.bashrc &amp;&amp; echo $MY_DATABASE_HOST')
</code></pre>

<p>Actually bashrc is executed. But it gets stopped because it's not running interactively through this:</p>

<pre><code>case $- in
     *i*) ;;
     *) return;;
esac
</code></pre>

<p>Now it works after I moved my environment variables at the top of my bashrc.</p>

<p>More detailed answer here <a href="https://github.com/fabric/fabric/issues/1519" rel="nofollow">https://github.com/fabric/fabric/issues/1519</a></p>

python fabric