forward / capify-ec2

Capify-EC2 is used to generate Capistrano namespaces and tasks from Amazon EC2 instance tags, dynamically building the list of servers to be deployed to.
https://rubygems.org/gems/capify-ec2
MIT License
198 stars 53 forks source link

Issue when having multiple roles and variables in each #54

Open eni9889 opened 10 years ago

eni9889 commented 10 years ago

If I define two roles:

ec2_roles   :name => :apiserver,
            :options => {:default=>true} ,
            :variables => {
                :domain => "apiserver.dev.instamotor.com",
                :thin_server_tag => "apiserver",
                :rackup_path => "apiserver/config.ru"
            }
ec2_roles   :name => :telegraph,
            :options => {:default=>true} ,
            :variables => {
                :domain => "telegraph.dev.instamotor.com",
                :thin_server_tag => "telegraph",
                :rackup_path => "telegraph/config.ru"
            }

And then have two tasks defined:

task :restart_apiserver, :roles => [:apiserver], :on_no_matching_servers => :continue do 
    thin_config_path = "#{current_path}/config/server/thin.#{domain}.yml"
    thin_rackup_path = "#{current_path}/#{rackup_path}"
    restart_thin  = "cd #{current_path} && bundle exec thin -C #{thin_config_path} -R #{thin_rackup_path} restart >> #{current_path}/log/#{thin_server_tag}.thin.log 2>&1"
    restart_nginx = "sudo service nginx restart" 

    run "#{restart_thin}"
    run "#{restart_nginx}"
end
task :restart_telegraph, :roles => [:telegraph] , :on_no_matching_servers => :continue do 
    thin_config_path = "#{current_path}/config/server/thin.#{domain}.yml"
    thin_rackup_path = "#{current_path}/#{rackup_path}"
    restart_thin  = "cd #{current_path} && bundle exec thin -C #{thin_config_path} -R #{thin_rackup_path} restart >> #{current_path}/log/#{thin_server_tag}.thin.log 2>&1"
    restart_nginx = "sudo service nginx restart" 

    run "#{restart_thin}"
    run "#{restart_nginx}"
end

When I call

cap integration telegraph apiserver deploy:restart

Only the apiserver variables get set in both the telegraph task and the apiserver task so both tasks end up calling the command

"cd /home/ubuntu/current && bundle exec thin -C /home/ubuntu/current/config/server/thin.apiserver.dev.instamotor.com.yml -R /home/ubuntu/current/apiserver/config.ru restart >> /home/ubuntu/current/log/apiserver.thin.log 2>&1"
Rylon commented 10 years ago

There was a bug with role chaining that should be addressed in v1.8.0.pre2, but I suspect this issue is deeper than that. I don't think the variables are being isolated into the roles they are defined with. I expect for now you would need to run each role individually:

cap integration telegraph deploy:restart cap integration apiserver deploy:restart