Chef cheat sheet: Difference between revisions

 
(20 intermediate revisions by the same user not shown)
Line 1: Line 1:
Opscode chef はまだまだ OSS の初期段階で、パワーユーザの時代であるらしい。hack, patch, push 的な感じっぽい。なのでお作法に則って、 Let's enjoy!!!
Opscode chef はまだまだ OSS の初期段階で、パワーユーザの時代であるらしい。hack, patch, push 的な感じっぽい。十分に使い物になるレベルにはあるし、使えばたくさん良いことがある。なのでお作法に則って、 Let's enjoy!!!


= メモ =
= メモ =
Line 17: Line 17:
  [http://acrmp.github.com/foodcritic/ Foodcritic - A lint tool for your Opscode Chef cookbooks]
  [http://acrmp.github.com/foodcritic/ Foodcritic - A lint tool for your Opscode Chef cookbooks]
  [https://github.com/etsy/foodcritic-rules Etsy's foodcritic rules]
  [https://github.com/etsy/foodcritic-rules Etsy's foodcritic rules]
ここで定義されているスタイルに合わせる。
ここで定義されているスタイルに合わせる。(最近 FC001 が違うという議論もあって面白い ;)
 
[http://wiki.opscode.com/display/chef/Opscode+Community+Summit+2 Opscode Community Summit 2 Session Documentation]
コミュニティサミットのドキュメント いろいろ参考になるかも。


== 導入 ==
== 導入 ==
Line 43: Line 46:
</syntaxhighlight>
</syntaxhighlight>


=== Client ===
=== Node ===
最近は omnibus install を推奨らしい
最近は omnibus install を推奨らしい


  [http://wiki.opscode.com/display/chef/Installing+Omnibus+Chef+Client+on+Linux+and+Mac Omnibus Installation]
  [http://wiki.opscode.com/display/chef/Installing+Omnibus+Chef+Client+on+Linux+and+Mac Omnibus Installation]


  sudo true && curl -L https://www.opscode.com/chef/install.sh | sudo bash
  <del>sudo true && curl -L https://www.opscode.com/chef/install.sh | sudo bash</del>


upgrade も ↑ で OK
upgrade も ↑ で OK


  sudo true && curl -L https://www.opscode.com/chef/install.sh | sudo bash -s -- -v 10.12.0
  <del>sudo true && curl -L https://www.opscode.com/chef/install.sh | sudo bash -s -- -v 10.12.0</del>


とか バージョン指定も可能 (いまのところ chef-client 10.14.2 は駄目っぽい)
とか バージョン指定も可能。(今は 10.16.2)
 
(2015/06/25 追記: 最近は curl | sudo bash はさすがにマズイという風潮が... なので公式サイトの表面からは消えてるようです。[https://downloads.chef.io/chef-client/])


== my recipes ==
== my recipes ==
Line 60: Line 65:
  [https://github.com/nxhack/chef nxhack / chef My recipes (opscode chef cookbooks) : Bootstrap - Configuration - Orchestration]
  [https://github.com/nxhack/chef nxhack / chef My recipes (opscode chef cookbooks) : Bootstrap - Configuration - Orchestration]


★ 料理のコツ ★
== ★ 料理のコツ ★ ==


一度だけ処理するとか、纏めて処理するとかは、action :nothing と notifies をうまく組み合わせると出来る
*一度だけ処理するとか、纏めて処理するとかは、action :nothing と notifies をうまく組み合わせると出来る


cookbook_file とか template とか file で create_if_missing の組み合わせと、さっきの action :nothing と notifies でいろいろ出来そう
*cookbook_file とか template とか file で create_if_missing の組み合わせと、さっきの action :nothing と notifies でいろいろ出来そう


cookbook_file と template は 出来た対象ファイルの内容をチェックして、同じなら処理しないという挙動になる。また file は content の組み合わせでは、 backup は取ってくれるが、内容のチェックはしてくれないようだ。
*cookbook_file と template は 出来た対象ファイルの内容をチェックして、同じなら処理しないという挙動になる。また file は content の組み合わせでは、 backup は取ってくれるが、内容のチェックはしてくれないようだ。
 
*execute, script, ruby_block とかの Resource に付ける名前は、同じ名前(重なる名前)は付けてはいけない
 
*secure_password を使う場合は、cookbook openssl を upload して recipe['openssl'] を run_list に追加する事


== knife-ec2 ==
== knife-ec2 ==
Line 72: Line 81:
knife.rb
knife.rb
<pre>
<pre>
# EC2:                                                                                                                    
# EC2:
knife[:aws_access_key_id]    = "---"
knife[:aws_access_key_id]    = "---"
knife[:aws_secret_access_key] = "---"
knife[:aws_secret_access_key] = "---"
Line 130: Line 139:
Bootstrap => Configuration => Orchestration の区別をして考える事が大事
Bootstrap => Configuration => Orchestration の区別をして考える事が大事


== role ==
== knife role ==
<pre>
<pre>
knife role from file ec2-common.json
knife role from file ec2-common.json
Line 140: Line 149:
(-Fj 使わない)
(-Fj 使わない)


== node ==
== knife node ==
<pre>
<pre>
knife node run_list add node01.egrep.jp 'role[node01],role[ec2-common]'
knife node run_list add node01.egrep.jp 'role[node01],role[ec2-common]'
</pre>
</pre>


== search ==
== knife search ==
<pre>
<pre>
knife search node '*:*' -a lsb.codename
knife search node '*:*' -a lsb.codename
Line 159: Line 168:
=== node object ===
=== node object ===
  [http://wiki.opscode.com/display/chef/Recipes#Recipes-CommonAutomaticAttributes Common Automatic Attributes]
  [http://wiki.opscode.com/display/chef/Recipes#Recipes-CommonAutomaticAttributes Common Automatic Attributes]
== knife-essentials ==
[https://github.com/jkeiser/knife-essentials Knife Essentials]
これは便利なので入れる方がよいそうです。
knife diff | fgrep diff
== berkshelf ==
[http://berkshelf.com/ Berkshelf - Manage a Cookbook or an Application's Cookbook dependencies]
便利っぽい
== spiceweasel ==
[http://wiki.opscode.com/display/chef/Spiceweasel Spiceweasel]
便利っぽい
== cookbook motd-tail ==
[https://github.com/opscode-cookbooks/motd-tail Updates motd.tail with Chef Roles]
node に login したときに、role を表示させる。


== WP CLI (WordPress Command Line Interface) ==
== WP CLI (WordPress Command Line Interface) ==
Line 174: Line 201:
wp plugin install 001-prime-strategy-translate-accelerator
wp plugin install 001-prime-strategy-translate-accelerator
wp plugin install backwpup
wp plugin install backwpup
wp plugin install db-cache-reloaded-fix
## wp plugin install db-cache-reloaded-fix
wp plugin install easy-fancybox
wp plugin install easy-fancybox
wp plugin install pushpress
wp plugin install pushpress