How would I reference the current server in a Capistrano task? I want to curl
a local file to clear the APC cache but the server does not listen on localhost
so I need the server's IP address.
For instance,
role :web, "1.1.1.1", "2.2.2.2", "3.3.3.3"
task :clear_apc, :role => :web do
run "curl http://#{WHAT_DO_I_PUT_HERE}/deploy/clearAPC.php"
end
What variable would I use so that when the task is run on 1.1.1.1 it curl
s http://1.1.1.1/deploy/clearAPC.php
but when run on 2.2.2.2 it calls curl
s http://2.2.2.2/deploy/clearAPC.php
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With