roundsman icon indicating copy to clipboard operation
roundsman copied to clipboard

Roles are ignored

Open maxim opened this issue 13 years ago • 2 comments

I have a task similar to this:

namespace :provision do
  task :redis, roles: :redis do
    roundsman.run_list('recipe[redis::server]')
  end
end

And roles like this

role :web, 'web01'
role :app, 'app01'
role :db, 'db01', primary: true
role :redis, 'redis01'

When I run cap provision:redis, I expect it to run recipe[redis::server] only on redis01 host (as per README). Instead, it runs on every host.

  * 01:27:09 == Currently executing `roundsman:chef:chef_solo'
 ** Now running recipe[redis::server]
  * executing "sudo -p 'sudo password: ' chef-solo -c /tmp/roundsman/solo.rb -j /tmp/roundsman/solo.json"
    servers: ["web01", "app01", "db01", "redis01"]
    [db01] executing command
    [web01] executing command
    [redis01] executing command
    [app01] executing command

I made a sanity check by adding this test task.

task :foo, roles: :redis do
  run "echo foo"
end

Running cap foo only ran this task on redis server, as expected.

maxim avatar Aug 15 '12 06:08 maxim

Turns out this is an ancient issue — capistrano won't scope roles of the nested task to the roles you specified on the caller task. Capistrano mailing list has a bunch of info on this, for example here is one possible solution. Worked ok for me to wrap each roundsman task in with_role block.

However, README is mistaken about this, and should be updated.

maxim avatar Aug 15 '12 15:08 maxim

this was really screwing things up for me.

I converting almost all of roundsman capistrano tasks to methods. I'm happy with the results, but feel I may have been able to use roundsman unchanged if I understood capistrano more.

Also of note, roles are ignored when running with a HOSTS environment variable. So I could installing a run_list into the wrong computer. fixed this by defining the run_list in the roles section. (it introduced minor other problems, but works very well for my process)

kbrock avatar Jan 17 '13 05:01 kbrock