I am trying to write a custom capistrano task that compiles my assets locally and then uses rsync to push them up to the production server. The problem is I cannot figure out how to access the IP address of my app server when using using capistrano’s run_locally.
Here is an excerpt from my config/deploy.rb:
server "[some_ip_address]", :web, :app, :db, :primary => true
...
namespace :assets do
desc 'Run the precompile task locally and rsync with shared'
task :precompile, :roles => :web, :except => { :no_release => true } do
run_locally "bundle exec rake assets:precompile"
run_locally "rsync -zvrh --progress -e 'ssh -i #{ssh_options[:keys][0]}' public/assets #{user}@$CAPISTRANO:HOST$:#{shared_path}"
puts "cleaning up locally compiled assets"
run_locally "bundle exec rake assets:clean"
end
end
The problem is that $CAPISTRANO:HOST$ does not expand out to the ip. I know I could hard code it, but I would like to do it properly.
Try to define capistrano variable with host IP and reference it anywhere in capistrano scripts to keep them DRY:
and in your task definition: