LoginSignup
8
8

More than 5 years have passed since last update.

chefの使い方

Posted at

chefののインストール

curl -L http://www.opscode.com/chef/install.sh | sudo bash

or

gem install chef

knifeの設定

knife configure

(*)"~/.chef/knife.rb"に保存される

cookbookの作成

$ knife cookbook create hello -o cookbooks
** Creating cookbook hello
** Creating README for cookbook: hello
** Creating CHANGELOG for cookbook: hello
** Creating metadata for cookbook: hello

レシピの修正

$ emacs cookbooks/hello/recipes/default.rb

chef-soloの設定

$ emacs ./localhost.json
$ emacs ./solo.rb

chef-soloの実行

$ sudo chef-solo -c solo.rb -j ./localhost.json

chef-soloの内容

  1. レシピを作って
  2. jsonファイルで実行するレシピを指定して
  3. chef-soloコマンドでそれを実行する

zshのインストール

recipes/dafult.rb
package "zsh" do
    action :install
end

template

erbで記述されたnginx等の設定ファイル
変数を埋め込むことができる
templates/default/..erb

attribute

templateに埋め込んだ変数の値を定義する
./localhost.json

vagrantのportの設定

デフォルトの場合、iptablesが有効になっているため、80番ポートを含むほとんどの外部ポートにlocalhost以外からアクセスできない。
そのため、"/etc/init.d/iptables stop"でiptablesごと止めれば良い。但し、本番では絶対にダメ!!
以下、chefでの設定

dafault.rb
service 'iptables' do
    action [:disable, :stop]
end

vagrantのネットワーク設定

config.vm.network :hostonly, "192.168.50.12"

ホストOSからゲストOSへネットワークアクセス機能をアクティブ化
ゲストOSのIP設定

sahara

vagrantにsandbox機能を追加してロールバックができる

git clone https://github.com/ryuzee/sahara.git
cd sahara
bundle install
bundle exec rake build
vagrant plugin install pkg/sahara-0.0.14.gem

knife-solo

リモートにrsyncで転送した後、chef-soloを実行してくれる。
(*)sshでログインする必要がなくなる

$ gem install knife-solo

chefのリポジトリ作成

$ knife solo init <リポ名>

berkshelf

chefのRubygems的存在

8
8
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
8
8