質問

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
役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top