Referencing the current server in Capistrano task
In Capistrano, tasks don't get executed once for each server, run executes your command on each server. Here is what you should do instead:
task :clear_apc, :role => :web do
find_servers_for_task(current_task).each do |current_server|
run "curl http://#{current_server.host}/deploy/clearAPC.php", :hosts => current_server.host
end
end
The accepted answer will work, but this one lets you access the servers as variables/methods
There's the magical $CAPISTRANO:HOST$
run "curl http://$CAPISTRANO:HOST$/deploy/clearAPC.php"
should do exactly what you want.
note: don't use it as a variable via string interpolation, capistrano will just replace the $CAPISTRANO:HOST$ in the string itself.
That's a very weird and (afaik) undocumented feature :-)
current_host = capture("echo $CAPISTRANO:HOST$").strip