Till
Till

Reputation: 1138

Capistrano 3: Get server info from role

Is it possible to access the hostname and user of a role without using on, so I don't have to nest the task below so ugly?

task :foo do
    on roles(:web) do |host|
        run_locally do
            execute :rsync, '-avzr', "/foobar", "#{host.user}@#{host.hostname}:/foobar"
        end
    end
end

Upvotes: 2

Views: 2282

Answers (1)

Till
Till

Reputation: 1138

Solved using Uri Agassi suggestion to use each:

task :foo do
    run_locally do
        roles(:web).each do |host|
            execute :rsync, '-avzr', "/foobar", "#{host.user}@#{host.hostname}:/foobar"
        end
    end
end

Upvotes: 5

Related Questions