Capistrano 3:在任务中使用服务器自定义变量 [英] Capistrano 3: use server custom variable in task
本文介绍了Capistrano 3:在任务中使用服务器自定义变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我具有多阶段多服务器设置,在我的任务中,我需要使用服务器名称
,例如在stagin.rb中,我有:
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
推荐答案
如果您想返回主机名/ IP,那么它将是
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
如果您要访问自定义属性(例如:name
),它们将存储在属性$ c $中c>
server
配置对象的哈希:只需使用 server.properties.name
而不是 server.hostname
。
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
.
这篇关于Capistrano 3:在任务中使用服务器自定义变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文