[Capistrano 3] - Using "extended server syntax" in deploy projects.

120 views
Skip to first unread message

Joe R

unread,
Sep 4, 2014, 3:19:37 PM9/4/14
to capis...@googlegroups.com
For political reasons, I've been asked to use Capistrano to deploy Chef Solo to a list of servers and interact with an API.
I'm new to Cap and new(ish) to Ruby. I'm looking for some help re: best way to use server definitions in Cap 3.

# Extended Server Syntax
   
# ======================
   
# This can be used to drop a more detailed server
   
# definition into the server list. The second argument
   
# is something that quacks like a hash and can be used
   
# to set extended properties on the server.
    server
'example.com', roles: %w{web app}, my_property: :my_value

vs
# Simple Role Syntax
   
# ==================
   
# Supports bulk-adding hosts to roles, the primary
   
# server in each group is considered to be the first
   
# unless any hosts have the primary property set.
    role
:app, %w{example.com}
    role
:web, %w{example.com}
    role
:db,  %w{example.com}

Which was the de facto standard in Cap 2.

My server list looks like this:
server '10.0.1.1', roles: [:hdp_ambari, :hdp_namenode, :hdp_hbase, :hdp_monitor_server, :hdp_zookeeper, :hdp_ganglia], internal:'ip-10-0-1-1.ec2.internal'
server
'10.0.1.2', roles: [:hdp_namenode_secondary, :hdp_datanode, :hdp_zookeeper, :hdp_ganglia], internal:'ip-10-0-1-2.ec2.internal'

I want to set :options to a hash of keys and internals corresponding to a given role. What's the best way to do this?

So desired output something like:
set :options, {
  default_filesystem
: "hdfs://ip-10-0-1-1.ec2.internal:8020",
  hbase_master
: 'ip-10-0-1-2.ec2.internal',
  job_history_server
: 'ip-10-0-1-1.ec2.internal',
  namenode
: 'ip-10-0-1-1.ec2.internal',
  namenode_secondary
: 'ip-10-0-1-2.ec2.internal',
  yarn_node
: 'ip-10-0-1-3.ec2.internal',
  zookeepers
: ['ip-10-0-1-1.ec2.internal', 'ip-10-0-1-2.ec2.internal']
}

For which I was thinking...
task :set_configuration_options do
 
# Fetching custom server.properties via http://tinyurl.com/ldkm7ov
  on roles
(:hdp_namenode), in: :parallel do |server|
    namenode_internal
= p server.internal
    filesystem_internal
= "hdfs://#{namenode_internal}:8020"
 
end


options
= {
  default_filesystem
: "#{filesystem_internal}",
  namenode
: "#{namenode_internal}"
}
end


set :options, options


But there's got to be a cleaner, better way, right? I'm having a tough time finding good examples or docs on this.



Relevant details:

Versions:
  • Ruby - 2.0.0p481
  • Capistrano - 3.0.1
  • Rake / Rails / etc - 10.1.0, 0.9.6
Platform:
  • Working on.... Mac OSX 10.9.2
  • Deploying to... CentOS 6.4
Logs:
  • Not relevant.  Asking for general advice, best practices re: extended server syntax.
Files:
  • Capfile, deploy.rb, and stage attached.
development.txt
deploy.txt
Capfile.txt
Reply all
Reply to author
Forward
0 new messages