Chefのお勉強2 - recipeの登録、利用
Workstation(今回はChefサーバ)で実行
利用するレシピはOPSCODEのgetting-started。レシピをChef Serverにアップロードする。
getting-startedはホームディレクトリに、chef-getting-started.txt を作成するレシピ。
# git clone https://github.com/opscode-cookbooks/getting-started.git # knife cookbook upload getting-started -o .
アップロードが出来たか確認する。
# knife recipe list getting-started
レシピをNodeで利用出来るようにする。
# knife node list <Node名が表示される> # knife node run_list add <Node名> "recipe[getting-started]" <Node名> run_list: recipe[getting-started] # knife node show <Node名> Node Name: <Node名> Environment: _default FQDN: <Node名(FQDN) > IP: < IPアドレス> Run List: recipe[getting-started] Roles: Recipes: Platform: centos 6.4 Tags:
実行環境(Node)で実行
# chef-client Starting Chef Client, version 11.4.4 [2013-05-18T20:14:26+09:00] INFO: *** Chef 11.4.4 *** [2013-05-18T20:14:26+09:00] INFO: [inet6] no default interface, picking the first ipaddress [2013-05-18T20:14:26+09:00] INFO: Run List is [recipe[getting-started]] [2013-05-18T20:14:26+09:00] INFO: Run List expands to [getting-started] [2013-05-18T20:14:26+09:00] INFO: Starting Chef Run for client2.localdomain [2013-05-18T20:14:26+09:00] INFO: Running start handlers [2013-05-18T20:14:26+09:00] INFO: Start handlers complete. resolving cookbooks for run list: ["getting-started"] [2013-05-18T20:14:26+09:00] INFO: Loading cookbooks [getting-started] Synchronizing Cookbooks: [2013-05-18T20:14:27+09:00] INFO: Storing updated cookbooks/getting-started/recipes/default.rb in the cache. [2013-05-18T20:14:27+09:00] INFO: Storing updated cookbooks/getting-started/attributes/default.rb in the cache. [2013-05-18T20:14:27+09:00] INFO: Storing updated cookbooks/getting-started/README.md in the cache. [2013-05-18T20:14:27+09:00] INFO: Storing updated cookbooks/getting-started/metadata.rb in the cache. - getting-started Compiling Cookbooks... Converging 1 resources Recipe: getting-started::default * template[/root/chef-getting-started.txt] action create[2013-05-18T20:14:27+09:00] INFO: Processing template[/root/chef-getting-started.txt] action create (getting-started::default line 20) [2013-05-18T20:14:27+09:00] INFO: template[/root/chef-getting-started.txt] updated content [2013-05-18T20:14:27+09:00] INFO: template[/root/chef-getting-started.txt] mode changed to 644 - create template[/root/chef-getting-started.txt] --- /tmp/chef-tempfile20130518-11703-1d23vid 2013-05-18 20:14:27.092977873 +0900 +++ /tmp/chef-rendered-template20130518-11703-1oxhmkm 2013-05-18 20:14:27.092977873 +0900 @@ -0,0 +1,5 @@ +Welcome to Chef! + +This is Chef version 11.4.4. +Running on centos. +Version 6.4. [2013-05-18T20:14:27+09:00] INFO: Chef Run complete in 0.324367186 seconds [2013-05-18T20:14:27+09:00] INFO: Running report handlers [2013-05-18T20:14:27+09:00] INFO: Report handlers complete Chef Client finished, 1 resources updated
レシピを実行した結果ファイルが出来たかを確認する。
# ls /root/chef-getting-started.txt /root/chef-getting-started.txt