読者です 読者をやめる 読者になる 読者になる

[自動 デプロイ] [capistrano]

OSは「ubuntu1010」

# apt-get install capistrano
# cap -V
Capistrano v2.5.9
# capify . 
[add] writing './Capfile'
[add] making directory './config'
[add] writing './config/deploy.rb'
[done] capified!

実行サーバ  :192.168.1.6
テストサーバ1:192.168.1.7
テストサーバ2:192.168.1.8
テストサーバ3:192.168.1.9

定義ファイル

set:application, "PROJ_NAME"
set:user, "test"
set:password, "test"

role:src, "192.168.1.6"
role:dst, "192.168.1.7","192.168.1.8","192.168.1.9"

task:test_task1, :roles => [:src, :dst] do
 run "echo TEST_TASK1"
end

task:test_task2, :roles => [:dst] do
 run "echo TEST_TASK2"
end

TEST_TASK1を実行

# cap -f deploy.rb test_task1
  * executing `test_task1'
  * executing "echo TEST_TASK1 $HOSTNAME"
    servers: ["192.168.1.6", "192.168.1.7", "192.168.1.8", "192.168.1.9"]
    [192.168.1.9] executing command
 ** [out :: 192.168.1.9] TEST_TASK1
    [192.168.1.8] executing command
    [192.168.1.7] executing command
 ** [out :: 192.168.1.8] TEST_TASK1
 ** [out :: 192.168.1.7] TEST_TASK1
    [192.168.1.6] executing command
 ** [out :: 192.168.1.6] TEST_TASK1
    command finished

TEST_TASK2を実行

# cap -f deploy.rb test_task2
  * executing `test_task2'
  * executing "echo TEST_TASK2"
    servers: ["192.168.1.7", "192.168.1.8", "192.168.1.9"]
    [192.168.1.8] executing command
    [192.168.1.7] executing command
 ** [out :: 192.168.1.8] TEST_TASK2
    [192.168.1.9] executing command
 ** [out :: 192.168.1.7] TEST_TASK2
 ** [out :: 192.168.1.9] TEST_TASK2
    command finished