まっしろけっけ

めもてきなやーつ

Berkshelfを使ってみる

Berkshelfを使うことでcookbookをgemっぽく扱うことができる。

berkshelfをinstall
$ cd chef-repo
$ vi Gemfile
+ source 'https://rubygems.org'
+ gem 'berkshelf'
$ bundle install

これでvendor以下にgemが格納される
これでberkshelfのinstallは終わり

berkshelfを使用してcookbookを取得
$ vi Berksfile
+ site :opscode
+ cookbook 'nginx'
$ bundle exec berks --path cookbooks
.....

--pathで格納先を指定

確認してみる

$ ls cookbooks/
apt		bluepill	build-essential	nginx		ohai		rsyslog		runit		yum		yum-epel

Berksfileでnginxのみを指定したが依存関係にあるcookbookも取得してくれます。

BerkshelfとVagrant

BerkshelfとVagrantを使用するとVagrantの初期化からchef soloの実行までを管理出来るよ
berks cookbookコマンドを使用する。

$ bundle exec berks cookbook kitchen
Could not locate Gemfile

Gemfile無いって言われたので作成してもう一回
※先ほどのchef-repoとは別のディレクトリで作業しています。

$ bundle exec berks cookbook kitchen
bundler: command not found: berks
Install missing gem executables with `bundle install`

bundle installしろって怒られた
ですよねー

$ bundle install
$ bundle exec berks cookbook kitchen
The source :rubygems is deprecated because HTTP requests are insecure.
Please change your source to 'https://rubygems.org' if possible, or 'http://rubygems.org' if not.
      create  kitchen/files/default
      create  kitchen/templates/default
      create  kitchen/attributes
      create  kitchen/definitions
      create  kitchen/libraries
      create  kitchen/providers
      create  kitchen/recipes
      create  kitchen/resources
      create  kitchen/recipes/default.rb
      create  kitchen/metadata.rb
      create  kitchen/LICENSE
      create  kitchen/README.md
      create  kitchen/Berksfile
      create  kitchen/Thorfile
      create  kitchen/chefignore
      create  kitchen/.gitignore
         run  git init from "./kitchen"
      create  kitchen/Gemfile
      create  kitchen/Vagrantfile

うまくいった!
なんかVagrantfileとかBerksfileとか色々作られた。
ファイルをみた感じchef-repo/cookbooks内の各cookbookと近い構成です。

とりあえずbundle installする

$ cd kitchen
$ bundle install

ファイルを更新していく

$ vi Berksfile
+ site :opscode
+ cookbook 'nginx'
$ vi Vagrantfile
+ config.vm.define :base do |base|
+   base.vm.network :private_network, ip: "192.168.50.50"
+ end

- config.vm.box_url = "https://dl.dropbox.com/u/31081437/Berkshelf-CentOS-6.3-x86_64-minimal.box"
+ config.vm.box_url = "https://github.com/2creatives/vagrant-centos/releases/download/v6.5.1/centos65-x86_64-20131205.box"

centos/releases/download/v6.5.1/centos65-x86_64-20131205.box"
    chef.run_list = [
        "recipe[kitchen::default]",
+        "recipe[nginx]"
    ]

Node Objectやrun_listはVagrantfileに記述するらしい。

準備が完了したので実行

$ bundle exec vagrant up
There are errors in the configuration of this machine. Please fix
the following errors and try again:

SSH:
* The following settings shouldn't exist: max_tries, timeout

Vagrant:
* Unknown configuration section 'berkshelf'.

error出たのでググったら
ここらへんここらへんが参考になったよ

$ vagrant plugin install vagrant-berkshelf
Installing the 'vagrant-berkshelf' plugin. This can take a few minutes...
Installed the plugin 'vagrant-berkshelf (1.3.7)'!

$ vagrant plugin install vagrant-omnibus
Installing the 'vagrant-omnibus' plugin. This can take a few minutes...
Installed the plugin 'vagrant-omnibus (1.3.0)'!

$ vi Vagrantfile
- config.ssh.max_tries = 40
- config.ssh.timeout = 120
+ config.omnibus.chef_version = :latest

もう一回実行してみる!

$ bundle exec vagrant provision
......
Stderr from the command:

なんかうまくいかん
downloading downloading https://www.getchef.com/chef/metadata?v=11.10.4&prerelease=false&p=el&pv=6&m=x86_64
ここらへんでDLできないっぽい
ネットワーク系の問題か?ということで確認

$ vagrant ssh
$ ping yahoo.co.jp
ping: unknown host yahoo.co.jp

外がみれてないっぽい
色々ググったがわからず再起動すればなおるかもって記事を見つけたのでmac再起動
再度挑戦!

$ vagrant up
$ vagrant ssh
$ nginx -v
nginx version: nginx/1.0.15

うまくいったnginxもちゃんとinstallされてました!
うれしいけど泣きたい
ネットワーク系で謎挙動があった(2時間はまった)

自作のcookbookを使用するとか色々やりたかったけど
今日はもうおしまい