LoginSignup
6
5

More than 5 years have passed since last update.

Capistranoでroleとserverの一覧を出力するタスクを書いた

Last updated at Posted at 2015-03-12

Capistranoのserver or role DSLで設定したサーバ、ロールの一覧を確認したいので以下のタスクを書いた。

roles(ロール名)というDSLが用意されているのでこれを使う。ロール名は:allをセットすることで全部取れる。

lib/capistrano/tasks/util.rake
namespace :util do
  desc 'List roles'
  task :list_roles do
    roles(:all).map{ |server| server.roles_array }.flatten.uniq.sort.each do |role|
      puts role
    end
  end

  desc 'List servers'
  task :list_servers do
    roles(:all).map(&:hostname).sort.each { |hostname| puts hostname }
  end

end

こういう感じで実行する

$ cap production util:list_roles
db
log
nagios
web
.
.

$ cap production util:list_servers
myserver1.local
myserver2.local
.
.

自分はサーバとロールを外から取ってきたデータで動的設定していて、そのデバッグ用途で書いてみた。

6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5