ardavis
ardavis

Reputation: 9895

How to use a different `default_env` per Capistrano role

In my deploy.rb, I have:

set :default_env, -> { {
  PATH: "some/path/to/stuff"
} }

I also have two servers:

server 'hostname1', roles: %{web app}, primary: true
server 'hostname2', roles: %{db}, no_release: true

For commands that run on hostname2, I'd like to use a different default_env, is that possible?

task :my_task do
  on roles :db do
    # do work
  end 
end

Upvotes: 0

Views: 455

Answers (2)

Sahil Bhalla
Sahil Bhalla

Reputation: 175

you can create a rake to setup different path based on the environment and then run the rake with default environment as parameter
task :setup, :roles => :db do
  run "rake developer:setup default_evironment=#{rails_env}"
  end

Upvotes: 0

Cong Chen
Cong Chen

Reputation: 2436

There isn't one way to use a different default_env directly, but you can rewrite its key-value pairs.

You should try this way:

task :my_task do
  on roles :db do
    with PATH: "/var/www/subdirectory" do
      # do work
    end 
  end
end

Upvotes: 2

Related Questions