itamae はじめました

itamae はじめました

Today's Goal

ローカルの recipe.rb を使って、 EC2 インスタンスに Nginx 立てる

Install into local machine

まず itamae をローカルマシンにインストール

$ gem install itamae

bundler なんかは使わず、 global に入れてしまうのがよいのかな。

Create recipe

てきとうな場所に recipe.rb を作る

package 'nginx' do
  action :install
end

DSLは、操作したいパッケージの block に書いていく。

action メソッドに symbol を渡すという書式。

Execution

ローカルの recipe を使って EC2 インスタンスに対して dry-run で実行してみる。

$ itamae ssh -u ec2-user -i ~/.ssh/your_keypari.pem -h xx.xx.xx.xx -n recipe.rb
 INFO : Starting Itamae...
 INFO : Recipe: /~~/recipe.rb
 INFO :   package[nginx] installed will change from 'false' to 'true'

nginx のインストール状態は false → true になるよって言われる。

-n を取って実際に動かしてみる。

   ・    ・    ・

EC2 インスタンスに接続して確認。

$ ssh -i ~/.ssh/your_keypair.pem ec2-user@xx.xx.xx.xx

$ which nginx
/usr/sbin/nginx

この時点でサービスとして登録されていない。

service 'nginx' do
  action [:enable, :start]
end
$ itamae ssh -u ec2-user -i ~/.ssh/your_keypair.pem -h xx.xx.xx.xx recipe.rb
 INFO : Starting Itamae...
 INFO : Recipe: /xx/recipe.rb
 INFO :   service[nginx] enabled will change from 'false' to 'true'
 INFO :   service[nginx] running will change from 'false' to 'true'

すでに package 'nginx' は済んでるので実行されていない。

$ ps aux | grep nginx
root     23685  0.0  0.0  58084  1016 ?        Ss   15:46   0:00 nginx: master process /usr/sbin
/nginx -c /etc/nginx/nginx.conf
nginx    23687  0.0  0.3  58456  3924 ?        S    15:46   0:00 nginx: worker process

プロセスもしっかり立ってる

f:id:kawakubox:20161209005955p:plain


Wiki みると、 BestPractice ってのがあるので、もう少し触ったら BestPractice に沿って書いてみよう。