Reputation: 7810
I want to instruct Capistrano to load environment variables that are defined on remote server. How can I do that?
It seems that when I export my environment variables inside .bashrc
file, they are not taken into account by Capistrano. Capistrano seems to be executing a /usr/bin/env
to create the environment for executing remote commands, but this does not seem to be loading the environment variables from .bashrc
.
Let me tell you also that I am using rvm-capistrano
too (just in case it might help).
Any clue?
Upvotes: 18
Views: 7161
Reputation: 2584
Capistrano actually does load .bashrc
. But near the top of the file you will find one of the following lines:
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
If you do any export
ing after the above lines, it will not be reached by Capistrano. The solution was simply to move my setup above this line—and Capistrano works how I want.
This solution was also noted at this GitHub issue.
Upvotes: 45
Reputation: 22296
You can pass your current environment variables to a remote execution with ssh by issuing:
env | ssh user@host remote_program
Also taken the example from here
on roles(:app), in: :sequence, wait: 5 do
within "/opt/sites/example.com" do
# commands in this block execute in the
# directory: /opt/sites/example.com
as :deploy do
# commands in this block execute as the "deploy" user.
with rails_env: :production do
# commands in this block execute with the environment
# variable RAILS_ENV=production
rake "assets:precompile"
runner "S3::Sync.notify"
end
end
end
end
looks like you can use with
set environment variables for your execution. So read your current environment variables and set them using with
.
Upvotes: 0
Reputation: 94
In Capistrano 3 it's set :default_env, { ... }
Like here:
set :default_environment, {
'env_var1' => 'value1',
'env_var2' => 'value2'
}
You can refer to this: Previous post..
Upvotes: -1
Reputation: 756
Capistrano doesn't load .bashrc
since it's not interactive shell. As far as I remember though it does load .bash_profile
though so you will probably have better luck using that.
Upvotes: -1