Itamae
を使ってみたので使い方やインストール方法をメモ。
Itamaeとは
@ryot_a_raiさんの制作したサーバー構成管理ツールです。
Chef-Solo
をよりシンプルにしたようなツールです。
インストール方法
gem install itamae
ItamaeでHello world
まずはtest_recipe.rb
を作って下のようにレシピを書きます。
execute "echo HelloWorld!" do command "echo HelloWorld" end
次は下コマンドでItamae
を実行します。
HelloWorld
が下から3行目に出力されている事が分かるかと思います。
-l
はログレベルのオプションです。
itamae_test$ itamae local test_recipe.rb -l debug INFO : Starting Itamae... DEBUG : Executing `mkdir -p /tmp/itamae_tmp`... DEBUG : exited with 0 DEBUG : Executing `chmod 777 /tmp/itamae_tmp`... DEBUG : exited with 0 INFO : Recipe: /Users/sugimoto/Desktop/itamae_test/test_recipe.rb DEBUG : execute[echo HelloWorld!] DEBUG : execute[echo HelloWorld!] action: run DEBUG : (in pre_action) DEBUG : (in set_current_attributes) DEBUG : (in show_differences) INFO : execute[echo HelloWorld!] executed will change from 'false' to 'true' DEBUG : Executing `echo HelloWorld`... DEBUG : exited with 0 DEBUG : stdout | HelloWorld DEBUG : This resource is updated. DEBUG : This resource is updated.
ItamaeをVagrantで実行
Vagrantfile
を作って下のように記述します。
VAGRANTFILE_API_VERSION = "2" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.box = "shimesaba" config.vm.box_url = "https://github.com/tommy-muehle/puppet-vagrant-boxes/releases/download/1.0.0/centos-6.6-x86_64.box" config.vm.network "private_network", ip: "192.168.33.11" end
終わったらサーバーを起動します。
vagrant up
test_recipe.rb
も少し修正します。
execute "echo HelloWorld!" do command "touch itamae_ok" end
Itamae
を実行すると、サーバーのホームディレクトリにitamae_ok
ファイルが生成されているかと思います。
itamae ssh --vagrant test_recipe.rb
Itamaeでnginxをインストール
test_recipe.rb
を下のように書き換えます。
package 'http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm' do not_if 'rpm -q nginx-release-centos-6-0.el6.ngx.noarch' end package "nginx" do action :install end
Itamae
を実行すればnginx
がインストールされるはずです。
itamae ssh --vagrant test_recipe.rb
その他のコマンド
下記事に情報がまとまっているのでこちらを見れば大体の事ができそうです。
Itamaeチートシート - Qiita
参考URL
ItamaeとVagrantでruby環境を構築する - Qiita
Itamae - Infra as Code 現状確認会 // Speaker Deck
itamae を使って CentOS6.5 に MySQL をインストールする時の注意 - Qiita