role/host variable

1,172 views
Skip to first unread message

Gerhardus Geldenhuis

unread,
Jan 21, 2009, 12:08:35 PM1/21/09
to Capistrano
Hi
Is there a variable that I can access to get the name of each server
in the role?

I want to do something like the following:

task :idfile, :roles => :testtct do
run "touch /tmp/#{testtct.name}"
end

Regards

Jamis Buck

unread,
Jan 21, 2009, 12:15:49 PM1/21/09
to capis...@googlegroups.com
You can get a list of all servers in a role like this:

servers = roles[:testtct].servers

That'll return an array of Capistrano::ServerDefinition objects. To get
the host name of a single server object, just do "server.host", e.g.:

puts "servers in testtct role:"
roles[:testtct].servers.each do |server|
puts "* #{server.host}"
end

However, what you REALLY want, is probably just to substitute the name
of the current server in the command, like so:

run "touch /tmp/$CAPISTRANO:HOST$"

Capistrano will always look for $CAPISTRANO:HOST$ in the command string,
and will replace it with the server's hostname at execution time.

- Jamis

Gerhardus Geldenhuis

unread,
Jan 21, 2009, 12:22:07 PM1/21/09
to Capistrano
Excellent! I am going to try that now.

Regards
Reply all
Reply to author
Forward
0 new messages