今夜はEngine Yardさんで行われるChefの勉強会に参加するものの、
実は一度もChef触った事ないので、それもどうかと思いますよね、と。
ついでに、先ほど基調講演だけ聴きにいった #CouchConf のCouchBase2.0の話がナイスな
感じだったので試してみたいな、と。
■ gemでChefのインストール
結構ガッツリいろいろ入りますね。
# gem install chef ~略~ Successfully installed mixlib-config-1.1.2 Successfully installed mixlib-cli-1.3.0 Successfully installed mixlib-log-1.4.1 Successfully installed mixlib-authentication-1.3.0 Successfully installed mixlib-shellout-1.1.0 Successfully installed systemu-2.5.2 Successfully installed ipaddress-0.8.0 Successfully installed ohai-6.16.0 Successfully installed rest-client-1.6.7 Successfully installed net-ssh-2.6.5 Successfully installed net-ssh-gateway-1.2.0 Successfully installed net-ssh-multi-1.1 Successfully installed highline-1.6.15 Successfully installed chef-11.4.0 14 gems installed ~略~
続いてchefのコマンドツールであるknifeを入れます。
# gem install knife-solo Fetching: archive-tar-minitar-0.5.2.gem (100%) Fetching: librarian-0.0.26.gem (100%) Fetching: knife-solo-0.2.0.gem (100%) Thanks for installing knife-solo! ~略~ Successfully installed archive-tar-minitar-0.5.2 Successfully installed librarian-0.0.26 Successfully installed knife-solo-0.2.0 3 gems installed
■ Chefの設定
Chefのクックブック用のディレクトリを作ります。
# mkdir -p /var/chef-solo/cookbooks
上記のディレクトリをsolo.rbにこんな感じで指定↓
# cat solo.rb file_cache_path "/var/chef-solo" cookbook_path "/var/chef-solo/cookbooks"
でもってレシピ指定。いつも通りのhogeな感じで。
# cat .chef/chef.json { "run_list": [ "recipe[hoge]" ] }
参考にさせていただいたブログにとりあえず一発叩いてみる的な記述があり、
こういうアプローチ好きなので、自分もとりあえず叩いてみます。
hogeっていうクックブックが無いよん的なログが出てますね。
# chef-solo -c /root/solo.rb -j /root/.chef/chef.json Starting Chef Client, version 11.4.0 Compiling Cookbooks... [2013-02-22T13:10:33+09:00] ERROR: Running exception handlers [2013-02-22T13:10:33+09:00] ERROR: Exception handlers complete Chef Client failed. 0 resources updated [2013-02-22T13:10:33+09:00] FATAL: Stacktrace dumped to /var/chef-solo/chef-stacktrace.out [2013-02-22T13:10:33+09:00] FATAL: Chef::Exceptions::CookbookNotFound: Cookbook hoge not found. If you're loading hoge from another cookbook, make sure you configure the dependency in your metadata
knife -hしてみたら↓こんなん出てきたので、
** SOLO COMMANDS ** knife solo cook [USER@]HOSTNAME [JSON] (options) knife solo prepare [USER@]HOSTNAME [JSON] (options) knife solo clean [USER@]HOSTNAME knife solo init DIRECTORY knife solo bootstrap [USER@]HOSTNAME [JSON] (options)
さっそくinitしてみます。
# knife solo init /var/chef-solo/ WARNING: No knife configuration file found ERROR: Errno::EEXIST: File exists - /var/chef-solo
なんか怒られました…。よく分からないけど # rm -r /var/chef-solo/ して
もっかいトライしてみます。
# knife solo init /var/chef-solo/ WARNING: No knife configuration file found
んで、出来たディレクトリをみてみると、、、
# ls -l /var/chef-solo/ total 24 drwxr-xr-x 2 root root 4096 Feb 22 13:20 cookbooks drwxr-xr-x 2 root root 4096 Feb 22 13:20 data_bags drwxr-xr-x 2 root root 4096 Feb 22 13:20 nodes drwxr-xr-x 2 root root 4096 Feb 22 13:20 roles drwxr-xr-x 2 root root 4096 Feb 22 13:20 site-cookbooks -rw-r--r-- 1 root root 319 Feb 22 13:20 solo.rb
アレ、ココにsolo.rb出来てんじゃん、、と。
#上記でディレクトリ作ったり、solo.rb書いたりしたのは不要だったということですね。。
# cat /var/chef-solo/solo.rb file_cache_path "/tmp/chef-solo" data_bag_path "/tmp/chef-solo/data_bags" encrypted_data_bag_secret "/tmp/chef-solo/data_bag_key" cookbook_path [ "/tmp/chef-solo/site-cookbooks", "/tmp/chef-solo/cookbooks" ] role_path "/tmp/chef-solo/roles"
/tmpはちょっとアレなので、”%s/tmp/var/” で全部/varにしてやります。
んま、そんなこんなでクックブックのhogeを作ります。
# cd /var/chef-solo/cookbooks # knife cookbook create hoge -o ./ WARNING: No knife configuration file found ** Creating cookbook hoge ** Creating README for cookbook: hoge ** Creating CHANGELOG for cookbook: hoge ** Creating metadata for cookbook: hoge
クックブックを作ったディレクトリに行ってみると↓のような感じ
cd /var/chef-solo/cookbooks/hoge # ls -l total 44 drwxr-xr-x 2 root root 4096 Feb 22 13:34 attributes -rw-r--r-- 1 root root 406 Feb 22 13:34 CHANGELOG.md drwxr-xr-x 2 root root 4096 Feb 22 13:34 definitions drwxr-xr-x 3 root root 4096 Feb 22 13:34 files drwxr-xr-x 2 root root 4096 Feb 22 13:34 libraries -rw-r--r-- 1 root root 272 Feb 22 13:34 metadata.rb drwxr-xr-x 2 root root 4096 Feb 22 13:34 providers -rw-r--r-- 1 root root 1431 Feb 22 13:34 README.md drwxr-xr-x 2 root root 4096 Feb 22 13:34 recipes drwxr-xr-x 2 root root 4096 Feb 22 13:34 resources drwxr-xr-x 3 root root 4096 Feb 22 13:34 templates
でもって、chef-soloを叩いてみると、以下のようにエラーが出なくなりました。
# chef-solo -c /var/chef-solo/solo.rb -j /root/.chef/chef.json Starting Chef Client, version 11.4.0 Compiling Cookbooks... Converging 0 resources Chef Client finished, 0 resources updated
クックブックの中に何もレシピないので0 resoures updatedです。
■ CouchBaseをインストール
とりあえず、当てずっぽうに、default.rbで↓やってみますw
# # Cookbook Name:: hoge # Recipe:: default # # Copyright 2013, YOUR_COMPANY_NAME # # All rights reserved - Do Not Redistribute # package "couchbase" do action :install end
↓怒られました…。バージョン書いてないとかそんな感じっぽい。
Recipe: hoge::default * package[couchbase] action install * No version specified, and no candidate version available for couchbase ================================================================================ Error executing action `install` on resource 'package[couchbase]' ================================================================================ Chef::Exceptions::Package ------------------------- No version specified, and no candidate version available for couchbase Resource Declaration: --------------------- # In /var/chef-solo/cookbooks/hoge/recipes/default.rb 9: package "couchbase" do 10: action :install 11: end Compiled Resource: ------------------ # Declared in /var/chef-solo/cookbooks/hoge/recipes/default.rb:9:in `from_file' package("couchbase") do action [:install] retries 0 retry_delay 2 package_name "couchbase" cookbook_name :hoge recipe_name "default" end
が、どうもググってくと、CouchBase入れるの、そんなに簡単じゃないみたい。
↓みると結構なボリューム…。
https://github.com/getaroom/chef-couchbase/tree/master/recipes
ってことで、Githubからゴッソリ持ってきて、、
# git fetch git@github.com:getaroom/chef-couchbase.git remote: Counting objects: 694, done. remote: Compressing objects: 100% (217/217), done. remote: Total 694 (delta 412), reused 671 (delta 389) Receiving objects: 100% (694/694), 107.55 KiB | 48 KiB/s, done. Resolving deltas: 100% (412/412), done. From github.com:getaroom/chef-couchbase * branch HEAD -> FETCH_HEAD
↓のようにしてchef-soloを叩いてみたら、
# chef-solo -c /var/chef-solo/solo.rb -j /root/.chef/chef.json
↓で落ちて、調べても分からず、ドハマリ…。
================================================================================ Recipe Compile Error in /var/chef-solo/cookbooks/couchbase/libraries/bucket_resource.rb ================================================================================ NoMethodError ------------- undefined method `attribute' for Chef::Resource::CouchbaseBucket:Class Cookbook Trace: --------------- /var/chef-solo/cookbooks/couchbase/libraries/bucket_resource.rb:9:in `' /var/chef-solo/cookbooks/couchbase/libraries/bucket_resource.rb:6:in `' /var/chef-solo/cookbooks/couchbase/libraries/bucket_resource.rb:5:in `' /var/chef-solo/cookbooks/couchbase/libraries/bucket_resource.rb:4:in `' Relevant File Content: ---------------------- /var/chef-solo/cookbooks/couchbase/libraries/bucket_resource.rb: 2: require File.join(File.dirname(__FILE__), "credentials_attributes") 3: 4: class Chef 5: class Resource 6: class CouchbaseBucket > attribute :bucket, :kind_of => String, :name_attribute => true 10: attribute :cluster, :kind_of => String, :default => "default" 11: attribute :exists, :kind_of => [TrueClass, FalseClass], :required => true 12: 13: attribute :memory_quota_mb, :kind_of => Integer, :callbacks => { 14: "must be at least 100" => lambda { |quota| quota >= 100 }, 15: } 16: 17: attribute :memory_quota_percent, :kind_of => Numeric, :callbacks => { 18: "must be a positive number" => lambda { |percent| percent > 0.0 },
↓とケースが似てるから、Chefの新しいバージョンだからなのかしら、、と。
https://github.com/bryanwb/chef-ark/issues/35
ちなみにバージョンは11.4.0。
# chef-solo -v Chef: 11.4.0
サクっとgemでUninstallカマします。
# gem uninstall chef You have requested to uninstall the gem: chef-11.4.0 knife-solo-0.2.0 depends on [chef (>= 10.12)] librarian-0.0.26 depends on [chef (>= 0.10)] If you remove this gems, one or more dependencies will not be met. Continue with Uninstall? [Yn] Y Remove executables: chef-client, chef-solo, knife, chef-shell, shef, chef-apply in addition to the gem? [Yn] Y Removing chef-client Removing chef-solo Removing knife Removing chef-shell Removing shef Removing chef-apply Successfully uninstalled chef-11.4.0
↓の10.24.0を入れ直します。
http://rubygems.org/gems/chef/versions/10.24.0
# gem install chef -v 10.24.0 Fetching: bunny-0.7.9.gem (100%) [Version 0.7.8] test suite cleanup (eliminated some race conditions related to queue.message_count) Fetching: moneta-0.6.0.gem (100%) Fetching: uuidtools-2.1.3.gem (100%) Fetching: chef-10.24.0.gem (100%) Successfully installed bunny-0.7.9 Successfully installed moneta-0.6.0 Successfully installed uuidtools-2.1.3 Successfully installed chef-10.24.0 4 gems installed
んでchef-soloを再び叩くと、、401 Unauthorizedって言われる。
どうも外にファイルを取りに行ってるようです。
================================================================================ Error executing action `create_if_missing` on resource 'remote_file[/var/chef-solo/couchbase-server-community_x86_64_1.8.0.deb]' ================================================================================ Net::HTTPServerException ------------------------ 401 "Unauthorized" Resource Declaration: --------------------- # In /var/chef-solo/cookbooks/couchbase/recipes/server.rb 27: remote_file File.join(Chef::Config[:file_cache_path], node['couchbase']['server']['package_file']) do 28: source node['couchbase']['server']['package_full_url'] 29: action :create_if_missing 30: end 31: Compiled Resource: ------------------ # Declared in /var/chef-solo/cookbooks/couchbase/recipes/server.rb:27:in `from_file' remote_file("/var/chef-solo/couchbase-server-community_x86_64_1.8.0.deb") do provider Chef::Provider::RemoteFile action [:create_if_missing] retries 0 retry_delay 2 path "/var/chef-solo/couchbase-server-community_x86_64_1.8.0.deb" backup 5 source "http://packages.couchbase.com/releases/1.8.0/couchbase-server-community_x86_64_1.8.0.deb" cookbook_name :couchbase recipe_name "server" end [2013-02-22T13:42:04+09:00] ERROR: Running exception handlers [2013-02-22T13:42:04+09:00] ERROR: Exception handlers complete [2013-02-22T13:42:04+09:00] FATAL: Stacktrace dumped to /var/chef-solo/chef-stacktrace.out [2013-02-22T13:42:04+09:00] FATAL: Net::HTTPServerException: remote_file[/var/chef-solo/couchbase-server-community_x86_64_1.8.0.deb] (couchbase::server line 27) had an error: Net::HTTPServerException: 401 "Unauthorized"
ということで、プロキシの設定をsolo.rbに追加して再びchef-solo叩いたら上記はクリア。
http_proxy "http://ホスト名:ポート" https_proxy "http://ホスト名:ポート"
が、今度はローカルっぽいところで400 Bad Request..
================================================================================ Error executing action `modify` on resource 'couchbase_settings[web]' ================================================================================ Net::HTTPServerException ------------------------ 400 "Bad Request" Cookbook Trace: --------------- /var/chef-solo/cookbooks/couchbase/libraries/client.rb:12:in `post' /var/chef-solo/cookbooks/couchbase/libraries/settings_provider.rb:17:in `action_modify' Resource Declaration: --------------------- # In /var/chef-solo/cookbooks/couchbase/recipes/server.rb 80: couchbase_settings "web" do 81: settings({ 82: "username" => node['couchbase']['server']['username'], 83: "password" => node['couchbase']['server']['password'], 84: "port" => 8091, 85: }) 86: 87: username node['couchbase']['server']['username'] 88: password node['couchbase']['server']['password'] 89: end Compiled Resource: ------------------ # Declared in /var/chef-solo/cookbooks/couchbase/recipes/server.rb:80:in `from_file' couchbase_settings("web") do action :modify retries 0 retry_delay 2 cookbook_name :couchbase recipe_name "server" settings {"username"=>"Administrator", "password"=>"", "port"=>8091} username "Administrator" group "web" end
↓ブラウザから見ると大丈夫そうに見えるのですが、、、
時間もないのでCouchBaseのサーバーの設定のレシピをコメントアウトして、
とにかく先に進む事にしました。。
80 #couchbase_settings "web" do 81 # settings({ 82 # "username" => node['couchbase']['server']['username'], 83 # "password" => node['couchbase']['server']['password'], 84 # "port" => 8091, 85 # }) 86 # 87 # username node['couchbase']['server']['username'] 88 # password node['couchbase']['server']['password'] 89 #end
今度はtest_buckets.rbっていうテストのレシピで…orz
================================================================================ Error executing action `create` on resource 'couchbase_bucket[modified % creation]' ================================================================================ NoMethodError ------------- undefined method `[]' for nil:NilClass Cookbook Trace: --------------- /var/chef-solo/cookbooks/couchbase/libraries/cluster_data.rb:6:in `pool_memory_quota_mb' /var/chef-solo/cookbooks/couchbase/libraries/bucket_provider.rb:68:in `new_memory_quota_mb' /var/chef-solo/cookbooks/couchbase/libraries/bucket_provider.rb:52:in `create_params' /var/chef-solo/cookbooks/couchbase/libraries/bucket_provider.rb:35:in `create_bucket' /var/chef-solo/cookbooks/couchbase/libraries/bucket_provider.rb:26:in `action_create' Resource Declaration: --------------------- # In /var/chef-solo/cookbooks/couchbase/recipes/test_buckets.rb 52: couchbase_bucket "modified % creation" do 53: bucket "modified_percent" 54: type "couchbase" 55: memory_quota_percent 0.1 56: 57: username node['couchbase']['server']['username'] 58: password node['couchbase']['server']['password'] 59: end 60: Compiled Resource: ------------------ # Declared in /var/chef-solo/cookbooks/couchbase/recipes/test_buckets.rb:52:in `from_file' couchbase_bucket("modified % creation") do action :create retries 0 retry_delay 2 cookbook_name :couchbase recipe_name "test_buckets" username "Administrator" type "couchbase" bucket "modified_percent" memory_quota_percent 0.1 cluster "default" end
諸事情で個人的にタイムアップになってしまったので、
node設定ののJSONからtest_bucketsを除く形にして、、、、w
{ "run_list": [ "recipe[couchbase]", "recipe[couchbase::server]", "recipe[couchbase::client]" ] }
↓のようにchef-soloを叩きなおすと、、、
# chef-solo -c /var/chef-solo/solo.rb -j /root/.chef/chef.json [2013-02-22T13:55:37+09:00] INFO: *** Chef 10.24.0 *** [2013-02-22T13:55:38+09:00] INFO: Setting the run_list to ["recipe[couchbase]", "recipe[couchbase::server]", "recipe[couchbase::client]"] from JSON [2013-02-22T13:55:38+09:00] INFO: Run List is [recipe[couchbase], recipe[couchbase::server], recipe[couchbase::client]] [2013-02-22T13:55:38+09:00] INFO: Run List expands to [couchbase, couchbase::server, couchbase::client] [2013-02-22T13:55:38+09:00] INFO: Starting Chef Run for hoge [2013-02-22T13:55:38+09:00] INFO: Running start handlers [2013-02-22T13:55:38+09:00] INFO: Start handlers complete. [2013-02-22T13:55:38+09:00] INFO: Processing remote_file[/var/chef-solo/couchbase-server-community_x86_64_1.8.0.deb] action create_if_missing (couchbase::server line 27) [2013-02-22T13:55:38+09:00] INFO: Processing dpkg_package[/var/chef-solo/couchbase-server-community_x86_64_1.8.0.deb] action install (couchbase::server line 32) [2013-02-22T13:55:38+09:00] INFO: Processing service[couchbase-server] action enable (couchbase::server line 34) [2013-02-22T13:55:38+09:00] INFO: Processing service[couchbase-server] action start (couchbase::server line 34) [2013-02-22T13:55:38+09:00] INFO: Processing directory[/opt/couchbase/var/lib/couchbase/logs] action create (couchbase::server line 39) [2013-02-22T13:55:38+09:00] INFO: Processing ruby_block[rewrite_couchbase_log_dir_config] action create (couchbase::server line 46) [2013-02-22T13:55:38+09:00] INFO: Processing directory[/opt/couchbase/var/lib/couchbase/data] action create (couchbase::server line 59) [2013-02-22T13:55:38+09:00] INFO: Processing couchbase_node[self] action modify (couchbase::server line 66) [2013-02-22T13:55:38+09:00] INFO: Processing couchbase_cluster[default] action create_if_missing (couchbase::server line 73) [2013-02-22T13:55:38+09:00] INFO: couchbase_cluster[default] created [2013-02-22T13:55:38+09:00] INFO: Processing remote_file[/var/chef-solo/libvbucket1_1.8.0.4-1_amd64.deb] action create_if_missing (couchbase::client line 33) [2013-02-22T13:55:38+09:00] INFO: Processing dpkg_package[/var/chef-solo/libvbucket1_1.8.0.4-1_amd64.deb] action install (couchbase::client line 38) [2013-02-22T13:55:38+09:00] INFO: Processing remote_file[/var/chef-solo/libvbucket-dev_1.8.0.4-1_amd64.deb] action create_if_missing (couchbase::client line 33) [2013-02-22T13:55:38+09:00] INFO: Processing dpkg_package[/var/chef-solo/libvbucket-dev_1.8.0.4-1_amd64.deb] action install (couchbase::client line 38) [2013-02-22T13:55:38+09:00] INFO: Processing remote_file[/var/chef-solo/libcouchbase1_1.0.4-1_amd64.deb] action create_if_missing (couchbase::client line 33) [2013-02-22T13:55:38+09:00] INFO: Processing dpkg_package[/var/chef-solo/libcouchbase1_1.0.4-1_amd64.deb] action install (couchbase::client line 38) [2013-02-22T13:55:38+09:00] INFO: Processing remote_file[/var/chef-solo/libcouchbase-dev_1.0.4-1_amd64.deb] action create_if_missing (couchbase::client line 33) [2013-02-22T13:55:38+09:00] INFO: Processing dpkg_package[/var/chef-solo/libcouchbase-dev_1.0.4-1_amd64.deb] action install (couchbase::client line 38) [2013-02-22T13:55:38+09:00] INFO: Chef Run complete in 0.397096206 seconds [2013-02-22T13:55:38+09:00] INFO: Running report handlers [2013-02-22T13:55:38+09:00] INFO: Report handlers complete # echo $? 0
んま、一応リターンコードがゼロという事で…ww
本当はFull Text Searchするところまでやりたかったのですが、到底及ばす…。
業務の空いた時間にチャチャッと出来るほど甘くはないかと…orz
ってか、2.0触ってみたかったのに、Couchbase Server 1.8.0がインストールされてます…。
まぁ、Chefに触れて、どんなもんかは少し分かった気がするので、
PHPerにも出来た 初めてのChef教室(http://kokucheese.com/event/index/74459/) 楽しみです!
#って、用事があって途中退席してしまうのですが…汗
日経BP社
売り上げランキング: 2,641
コメント