LoginSignup
628
622

More than 5 years have passed since last update.

Chef-soloからItamaeに完全移行した話

Last updated at Posted at 2015-02-22

2016/04/24 
Itamae meetup
Databag > itamae-secret Consul 
http://www.slideshare.net/tsuyoshitorii5/itamae-meetup-vol1public



Chef-solo 1
Itamae




: Itamae


https://github.com/itamae-kitchen/itamae
Chef 
Chef
 

Chef
Itamae
Itamae gem install  1


Itamae Quick Start

# install
gem install itamae

# 適当なレシピ作る
echo "package 'sl'" > recipe.rb

# レシピ実行(ローカルホスト)
itamae local recipe.rb
# レシピ実行(リモートホスト)
itamae ssh -u hogeuser -h xxx.xxx.xxx.xxx recipe.rb
# attributeを定義したjsonを指定して実行
itamae local -j node.json recipe.rb
# レシピを複数つなげて実行
itamae local recipe01.rb recipe02.rb recipe03.rb

# dry-run
itamae local --dry-run recipe.rb
# ohai情報を参照する場合
itamae local --ohai recipe.rb


Itamae


 vagrant-aws + berkshelf + chef-solo 



(一)

(二)chef-zero

1. 


Vagrant-aws 2
berkshelfrsyncchef-solo

2. chef-zero 


chef-solochef-zero使


 

...使

2Itamae 
(Ansibleyaml)




(一)

(二)

1. 


1
Itamae
rakevagrant 


(一)configvagrantvm

(二)nodes/vm.json 

(三)rake aws:up vm=vm VM

(四)rake aws:provision vm=vm (chef-solo)

(五)rake aws:spec vm=vm 

(六)rake aws:create_ami vm=vm AMI

2. 


Ansible





2015/5/25 
itamaeWiki


chef
PROJECT_ROOT/
  cookbooks/    # クックブック群
  nodes/        # vm毎のnode.json
  roles/        # ロール群
  entrypoint.rb # Itamaeから実行されるレシピのエントリポイント(後程説明)
  Gemfile       # Itamaeプラグインなどの依存が書かれたGemfile

クックブック毎

実はここは割とゆるめの規約にしてあって、
レシピ数行で済むようなものはattributesやtemplatesも作らずに
1ファイルで済ませたりすることもあります。
ファイルが増えてきて見通しが悪くなってきたら以下のようにする感じですね。

<cookbook_name>
  attributes.rb   # attributesをまとめたファイル
  xxx_recipe.rb   # なんかレシピ
  yyy_recipe.rb   # なんかレシピ
  templates/      # テンプレートファイル
    xxx.conf.erb

この構成にした場合、
手動でincludeしておかないと属性情報が利用できないため
recipeファイルの先頭でattribute.rbをincludeする必要があります。
1行増えるだけだしまあこのくらいなら許容範囲かと。

include_recipe './attribute.rb'
...

attribute

consulbin




https://github.com/toritori0318/itamae-sample-project


VagrantshellItamae


vagrant-itamae
itamae
syncItamae
Itamaelocal

()Itamae

entrypoint.rb


chef-solonodes.jsonrecipes
Itamae


node["recipes"] = node["recipes"] || []

# レシピを順番にinclude_recipeするだけ
node["recipes"].each do |recipe|
  include_recipe recipe
end

attributeファイルについて


attribute
node.json
attirbute

2015/2/23 
# "td_agent" 項目を初期化
node["td_agent"] = node["td_agent"] || {}

# node['td_agent']['includes']が入力済みであればそちらを優先
node['td_agent']['includes'] = node['td_agent']['includes'] || []
...

プロジェクト全体で共通化しているレシピはプラグイン化する

全体で共通化しているレシピはプラグインとして作り、
プライベートリポジトリなどにおいておくと良いでしょう。
するとプロジェクト毎のレシピの見通しがよくなります。

Gemfileに以下のような記述をしておいて、bundlerで管理します。

# 独自のプライベートリポジトリに置かれた共通レシピなど
gem 'itamae-plugin-recipe-company-base', :git => 'git://hogehoge.com/fuga/itamae-plugin-recipe-company-base.git'



 include_recipe 


include_recipe使
attributerole
chef





:)
便使Itamae使
github 3
https://github.com/toritori0318/itamae-plugin-recipe-supervisor
https://github.com/toritori0318/itamae-plugin-recipe-consul







cookbookchef


gem install itamae 



 t2.small
t2.micro 


使

Itamae使

(package/execute/template/service)


Itamae


Chef




Chefweb
Itamae()

:)

DataBag


Databag

使
http://qiita.com/nownabe/items/8576c17f864aeefa03d0




Itamae 




ChefItamae

: mode


mode  string
# Chef
template 'a' do
  mode 0644  # 数値でも文字列でもOK
end

# Itamae
template 'a' do
  mode '644' # 文字列限定
end

リソース全般: only_if/not_ifの書き方

ブロックではなく、文字列を指定する必要がある。

# Chef
template "a" do
  not_if { File.exists?("/tmp/a.conf") }  # ブロックでも文字列でもOK
end

# Itamae
template "a" do
  not_if "test -e /tmp/a.conf" # 文字列のみOK
end

リソース全般: notifiesのタイミング指定

:delayed ではなく :delay になっている。
(デフォルト指定がdelayなので、typoしてても実質無害ではあるが…)

# Chef
template "a" do
  notifies :restart, "service[httpd]", :delayed
end

# Itamae
template "a" do
  notifies :restart, "service[httpd]", :delay
end

directory: recursive属性が無い

# recursive付けなくてもOK
directory "/tmp/hoge/fuga" do
  action :create
end

同じリソースでも出来る事が異なる

というか異なる部分はかなり多いので
きちんとドキュメントを読んだほうが良いでしょう。


Ref



  1. この辺りのブログにも書いてます ( http://d.hatena.ne.jp/toritori0318/20130916/1379355060 ) ( http://d.hatena.ne.jp/toritori0318/20140829/1409296637

  2. vagrant-cachierも利用済み。 

  3. API変える予定ありますしアルファ版ということでご容赦ください:( 

628
622
1

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
628
622