Chef cheat sheet: Difference between revisions

From misc notes
Jump to navigation Jump to search
Line 28: Line 28:
<syntaxhighlight>
<syntaxhighlight>
ln -s /var/lib/gems /usr/lib/ruby/
ln -s /var/lib/gems /usr/lib/ruby/
gem install builder --ignore-dependencies
gem install fog --ignore-dependencies
gem install fog --ignore-dependencies
gem install knife-ec2 --ignore-dependencies
gem install knife-ec2 --ignore-dependencies

Revision as of 09:52, 21 June 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 に汎用性を持たせようとする動きはあるらしいが、現状では無理っぽい。というか、使うことによってベストプラクティスを模索している段階かも。

導入

Hosted Chef Server の Free 版で 5 node まで使えるので、これで勉強する。

Hosted Chef
echo 'deb http://apt.opscode.com/ lucid-0.10 main' | sudo tee /etc/apt/sources.list.d/opscode.list
wget -qO - http://apt.opscode.com/packages@opscode.com.gpg.key | sudo apt-key add -
sudo aptitude update
sudo aptitude -y install chef
ln -s /var/lib/gems /usr/lib/ruby/
gem install builder --ignore-dependencies
gem install fog --ignore-dependencies
gem install knife-ec2 --ignore-dependencies

(opscode の パッケージで構成するばあい、apt vs. gem の構図に陥るので、knife-ec2 を gem から入れる場合は --ignore-dependencies をつける) (まだはまり中)

my recipes

普段やっている設定を cookbook にまとめ中

nxhack / chef My recipes (opscode chef cookbooks) : Bootstrap - Configuration - Orchestration

knife-ec2

knife.rb

# EC2:                                                                                                                      
knife[:aws_access_key_id]     = "---"
knife[:aws_secret_access_key] = "---"
knife[:flavor]                = "t1.micro"
knife[:image]                 = "ami-0baf7662"
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 -d ubuntu10.04-apt-ec2
knife ec2 server create -N node01.egrep.jp -x ubuntu -r "role[node01],role[ec2-common]" -d ubuntu10.04-apt-ec2

knife bootstrap

すでに稼働しているインスタンスに opscode の リポジトリから chef client を node 名を指定してインストールする。

knife bootstrap IPADDRESS -N node01.egrep.jp -i ~/.ssh/ssh_key.pem -x ubuntu --sudo -d ubuntu10.04-apt
Custom Knife Bootstrap Script

Bootstrap => Configuration => Orchestration の区別をして考える事が大事

role

knife role from file ec2-common.json
knife role show ec2-common -F json

node

knife node run_list add node01.egrep.jp 'role[node01],role[ec2-common]'

Recipe

node object

Common Automatic Attributes