/var/log/messages

Nov 25, 2013 - 2 minute read - Comments - DevOps

GitHub に登録したプロトタイプを使ってみる

とりあえず手元の Mavericks な MBA では無理なので某仮想リソースで。起動できたら clone します。

$ git clone https://github.com/yamanetoshi/knife-solo-prototype.git

で、~/.ssh/config を以下にしておいて

Host melody
  HostName 10.1.3.5
  User devops
  identityfile ~/.ssh/devopsOkinawa.key

Hostname は適宜読み換えてください。あと、鍵もコピィ必要。これで ssh devops@melody で接続できれば準備は OK です。

で、bundle install なんですが、某所の仮想リソースは bundler が入ってなくて

$ sudo gem i bundler
$ sudo rebenv rehash

という手続き必要。あと、この時点で chef-repo ディレクトリを git 管理にしておくと良いかもしれません。

あと、bundle install は –path 付けること。後天性記憶不全でつい忘れてしまいますorz

$ bundle install --path vendor/bundle

で、chef-repo の中で git init して git status したら以下なカンジでした。

$ git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       .chef/
#       .gitignore
#       Berksfile
#       data_bags/
#       environments/
#       nodes/
#       roles/
#       site-cookbooks/

とりあえず initial commit な commit を作っておいて knife solo prepare をば。

$ bundle exec knife solo prepare melody

リモホに Chef が導入されて nodes/melody.json が作成されてます。ので以下。

$ git add nodes/melody.json
$ git commit -m 'Add node json file'

クックブック作成

ええと、以下なのか。nginx で云々、ってことで。クックブック新規作成。

$ knife cookbook create nginx -o site-cookbooks

で、site-cookbooks/nginx/recipes/default.rb を編集。Chef 本によると以下を、とのこと。

package "nginx" do 
  action :install
end
service "nginx" do
  supports :status => true, :restart => true, :reload => true 
  action [ :enable , :start ]
end
template "nginx.conf" do
  path "/etc/nginx/nginx.conf" source "nginx.conf.erb"
  owner "root"
  group "root"
  mode 0644
  notifies :reload , 'service[nginx]'
end

詳細略。で、テンプレを site-cookbooks/nginx/templates/default/nginx.conf.erb に投入とのこと

user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log; 
pid /var/run/nginx.pid;
events {
  worker_connections 1024;
}
http {
  include /etc/nginx/mime.types; 
  default_type application/octet -stream;
server {
  listen <%= node['nginx']['port'] %>; 
  server_name localhost;
  location / {
    root /usr/share/nginx/html;
    index index.html index.htm;
  }
}

で、chef-repo/nodes/melody.json を以下にするのか。

{
  "nginx": {
    "port" : 80 
  },
  "run_list": [ 
    "nginx"
  ] 
}

で、以下なのか。

$ bundle exec knife solo cook melody

ちなみにカレントディレクトリは chef-repo の中でないと駄目らしい。

結果

Chef はエラーを吐いてたのですがリモホでは正常稼動してます。とりあえず流れ的にはこんなもん、ってことで微妙ですがばたばた気味なのでエントリ投入。

TODO 控え EoPL の Exercise 2.23

comments powered by Disqus