Capistrano 3: use server custom variable in task

独自空忆成欢 提交于 2019-12-06 21:53:37

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/21233873/capistrano-3-use-server-custom-variable-in-task

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!