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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With