web系な備忘録

私が忘れてもブログがあるもの

「入門chef solo」で詰まったところメモ

Amazon.co.jp: 入門Chef Solo - Infrastructure as Code eBook: 伊藤直也: Kindleストア

 買いました。  読みながらコマンドを試していたのですが、chef soloのバージョンが書籍よりかなり進んでいて、そのまま使えないコマンドが結構ありました。

 ということでメモです。書籍の補完資料として。

サーバの状態をセーブできるようにする

 vagrantをセットアップした後の部分。  書籍には vagrant gem install sahara とあったけど、現在はpluginを使うらしい。

vagrant plugin install sahara

参照: http://ri.hateblo.jp/entry/2013/10/29/013359

knife-soloの導入

$ git clone git://github.com/matschaffer/knife-solo.git
$ cd knife-solo/            
$ rake install
rake aborted!
WARNING:  See http://guides.rubygems.org/specification-reference/ for help
ERROR:  While executing gem ... (Gem::InvalidSpecificationException)
(略)

 ダメだった。submoduleの取り込みが必要だったようなのでやる。

$ git submodule init
$ git submodule update

$ rake install
knife-solo 0.5.0 built to pkg/knife-solo-0.5.0.gem.
rake aborted!
Couldn't install gem, run `gem install /Users/.../knife-solo/pkg/knife-solo-0.5.0.gem' for more detailed output

$ gem install /Users/.../knife-solo/pkg/knife-solo-0.5.0.gem
ERROR:  While executing gem ... (Gem::RemoteFetcher::UnknownHostError)
    no such name (https://api.rubygems.org/quick/Marshal.4.8/pry-0.9.7.1-java.gemspec.rz)

 pryがないらしいので入れる。入れて試すとアレがないコレがないと言われるので都度入れていく。  結果的に以下の処理が必要だった。

$ gem install pry
$ gem install mime-types
$ gem install json

 これでknife-soloが入るようになる。

$ gem install /Users/violet1101/Development/SakuraClone/knife-solo/pkg/knife-solo-0.5.0.gem

$ rake install
knife-solo 0.5.0 built to pkg/knife-solo-0.5.0.gem.
knife-solo (0.5.0) installed.

 。。。入ったはずなんだけどコマンドが見つからなかったので、こちらの記事に従ってパスを追加した。

installしたはずなのにコマンドが見つからない時の対処法φ(・・*) - Qiita

knife solo cook host-name ができなかった

$ knife solo cook melody
Running Chef on melody...
Checking Chef version...
Uploading the kitchen...
Generating solo config...
Running Chef...
[2014-09-09T15:01:11+00:00] WARN: 
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
SSL validation of HTTPS requests is disabled. HTTPS connections are still
encrypted, but chef is not able to detect forged replies or man in the middle
attacks.

To fix this issue add an entry like this to your configuration file:

-```
  # Verify all HTTPS connections (recommended)
  ssl_verify_mode :verify_peer

  # OR, Verify only connections to chef-server
  verify_api_cert true
-```

To check your SSL configuration, or troubleshoot errors, you can use the
`knife ssl check` command like so:

-```
  knife ssl check -c /home/vagrant/chef-solo/solo.rb
-```

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Starting Chef Client, version 11.16.0
Compiling Cookbooks...
Converging 0 resources

Running handlers:
Running handlers complete
Chef Client finished, 0/0 resources updated in 8.362882324 seconds
$ vim .chef/knife.rb

  9 cookbook_path            ['./cookbooks', './site-cookbooks'] 
 10 ssl_verify_mode          :verify_peer 
  • 普通にinitしただけではsite-cookbooksが指定されていなかったので追記。
  • 上記エラーメッセージで促された様にssh設定を追記。

サードパーティレシピの追加方法

 まだサーバに入っていないackコマンドを追加して動作を確認する。

$ knife cookbook create ack -o site-cookbooks

 手動で2箇所修正。

$ vim nodes/melody.json
  2   "run_list": [ 
  3     "recipe[ack]"  ←追記
  4   ], 
$ vim site-cookbooks/ack/recipes/default.rb 
 10 package "ack" do 
 11     action :install 
 12 end 

 vagrantに適用させる。

$ knife solo cook melody
Running Chef on melody...
Checking Chef version...
Uploading the kitchen...
Generating solo config...
Running Chef...
Starting Chef Client, version 11.16.0
Compiling Cookbooks...
Converging 1 resources
Recipe: ack::default
  * package[ack] action install
    - install version 2.12-2.el6 of package ack

Running handlers:
Running handlers complete
Chef Client finished, 1/1 resources updated in 24.873520682 seconds

 実際にackコマンドが入っているか確認する。

$ ssh melody
$ ack
(ヘルプ的な文章)

 できたヽ(゚∀゚)ノ