Chef cheat sheet: Difference between revisions
(→Client) |
(→Client) |
||
Line 48: | Line 48: | ||
[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://opscode.com/chef/install.sh | sudo bash | sudo true && curl -L https://www.opscode.com/chef/install.sh | sudo bash | ||
upgrade も ↑ で OK | upgrade も ↑ で OK |
Revision as of 08:40, 13 September 2012
Opscode chef はまだまだ OSS の初期段階で、パワーユーザの時代であるらしい。hack, patch, push 的な感じっぽい。なのでお作法に則って、 Let's enjoy!!!
メモ
information
自分で漁ること
Chef Wiki @tily さんの日本語訳 Opscode Mailing Lists Opscode github Opscode Open Source Ticket Tracking
あとは、公開されている cookbook で何とかなるわけでは無く、それを参考にして自分でバンバン書くのが吉
cookbook に汎用性を持たせようとする動きはあるらしいが、現状では無理っぽい。というか、使うことによってベストプラクティスを模索している段階かも。
Foodcritic - A lint tool for your Opscode Chef cookbooks Etsy's foodcritic rules
ここで定義されているスタイルに合わせる。
導入
Server
Hosted Chef Server の Free 版で 5 node まで使えるので、これで勉強する。
Hosted Chef
Workstation
Workstation は事実上 gem で手管理のほうが関連するツールを考えるといいかも
Workstation Setup for Debian and Ubuntu
しかも ruby 1.9.2 以上のほうがよさげ
Next Generation Ubuntu Ruby Packages
sudo apt-add-repository ppa:brightbox/ruby-ng
sudo aptitude update
sudo aptitude install ruby ruby-dev libopenssl-ruby rdoc ri irb build-essential wget ssl-cert curl
sudo gem install chef --no-ri --no-rdoc
sudo gem install knife-ec2 --no-ri --no-rdoc
sudo gem install foodcritic --no-ri --no-rdoc
sudo aptitude -y install git-core
Client
最近は omnibus install を推奨らしい
Omnibus Installation
sudo true && curl -L https://www.opscode.com/chef/install.sh | sudo bash
upgrade も ↑ で OK
sudo true && curl -L https://www.opscode.com/chef/install.sh | sudo bash -s -- -v 10.12.0
とか バージョン指定も可能
my recipes
普段やっている設定を cookbook にまとめ中
nxhack / chef My recipes (opscode chef cookbooks) : Bootstrap - Configuration - Orchestration
★ 料理のコツ ★
一度だけ処理するとか、纏めて処理するとかは、action :nothing と notifies をうまく組み合わせると出来る
cookbook_file とか template とか file で create_if_missing の組み合わせと、さっきの action :nothing と notifies でいろいろ出来そう
cookbook_file と template は 出来た対象ファイルの内容をチェックして、同じなら処理しないという挙動になる。また file は content の組み合わせでは、 backup は取ってくれるが、内容のチェックはしてくれないようだ。
knife-ec2
knife.rb
# EC2: knife[:aws_access_key_id] = "---" knife[:aws_secret_access_key] = "---" knife[:flavor] = "t1.micro" knife[:image] = "ami-d5e54dbc" knife[:aws_ssh_key_id] = "EC2_Key_Pairs_Name"
ssh-agent
eval `ssh-agent` ssh-add ~/.ssh/ssh_key.pem
(残っている ssh-agent への attach)
export SSH_AGENT_PID=`pgrep ssh-agent` export SSH_AUTH_SOCK=`ls /tmp/ssh-*/agent.*`
knife ec2 server create -N node01.egrep.jp -x ubuntu
knife ec2 server create -N node01.egrep.jp -x ubuntu -r "role[node01],role[ec2-common]" -Z us-east-1d
Custom Knife Bootstrap Script distro で指定するのもあり。(今は、OmniBus Installer を使った標準のままの chef-full.erb でやるようがよさげ)
knife ec2 server create -N node01.egrep.jp -x ubuntu -d ubuntu10.04-omnibus-ec2
knife ec2 server create -N node01.egrep.jp -x ubuntu -r "role[node01],role[ec2-common]" -d ubuntu10.04-omnibus-ec2 -Z us-east-1d
node name を指定して起動したインスタンスを停止する際に、chef-server に自動登録した node と client も同時に消したい場合
knife ec2 server delete i-xxxxxxxx -N node01.egrep.jp -P
knife bootstrap
すでに稼働しているインスタンスに opscode の リポジトリから chef client を node 名を指定してインストールする。
knife bootstrap IPADDRESS -N node01.egrep.jp -i ~/.ssh/ssh_key.pem -x ubuntu --sudo -d chef-full
Custom Knife Bootstrap Script
Bootstrap => Configuration => Orchestration の区別をして考える事が大事
role
knife role from file ec2-common.json
knife role show ec2-common -F json
(-Fj 使わない)
node
knife node run_list add node01.egrep.jp 'role[node01],role[ec2-common]'
search
knife search node '*:*' -a lsb.codename
chef-client
run_list を指定して起動する場合
chef-client -o 'role[node01],role[ec2-common]'
Recipe
node object
Common Automatic Attributes
WP CLI (WordPress Command Line Interface)
WordPress の configration にコレは便利そう。(テスト中)
A command line interface for WordPress
wp-cli の chef recipe をナンチャッテで書いてみた。(推敲中)
https://github.com/nxhack/chef/tree/master/cookbooks/conf-WordPress-cli
wp core install --url='http://www.example.com/blog' --title='MY SITE' --admin_email='admin@example.com' --admin_password='pass' wp plugin install apc wp plugin install 001-prime-strategy-translate-accelerator wp plugin install backwpup wp plugin install db-cache-reloaded-fix wp plugin install easy-fancybox wp plugin install pushpress wp plugin install syntaxhighlighter wp plugin install tinymce-advanced wp plugin install wp-crontrol wp plugin install wp-page-numbers wp plugin install wp-social-bookmarking-Light wp plugin install wptouch wp plugin activate akismet wp plugin activate wp-multibyte-patch ## wp plugin activate apc (!!! mv ./object-cache.php ../../ ) wp plugin activate 001-prime-strategy-translate-accelerator wp plugin activate backwpup ## wp plugin activate db-cache-reloaded-fix wp plugin activate easy-fancybox wp plugin activate pushpress wp plugin activate syntaxhighlighter wp plugin activate tinymce-advanced wp plugin activate wp-crontrol wp plugin activate wp-page-numbers wp plugin activate wp-social-bookmarking-Light wp plugin activate wptouch