Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capistrano 3: use server custom variable in task

I have multi-stage multi-server setup and in my task I need to use server name e.g. in stagin.rb I have:

set :stage, :staging
# Define servers
server 'xxx.xx.xx.xxx', user: 'deploy', roles: %w{app}, name: 'app1'
server 'xxx.xx.xx.yyy', user: 'deploy', roles: %w{app}, name: 'app2'

and I want to use that "name" variable in my task:

task :configure do
  on roles(:app), in: :parallel do
  # how do I get server name here?
  end
end
like image 798
a.yastreb Avatar asked Jan 20 '14 12:01

a.yastreb


1 Answers

If you want to return the hostname / IP, then it will be

task :configure do
  on roles(:app), in: :parallel do |server|
    p server.hostname # server hostname should be in here
  end
end

If you would like to access custom properties, like :name in this particular case, they are stored in the properties hash of the server configuration object: just use server.properties.name instead of server.hostname.

like image 182
bredikhin Avatar answered Nov 13 '22 23:11

bredikhin