2011年7月21日木曜日

coherence cookbookの作成②

今回やること
・cookbookの名前変更
・recipeはdefault.rbを使用していたがインストール専用のrecipeを作成する。
・既にcoherenceがインストールされている場合に、chef runしたときに再度インストールしないようにする。

cookbookの名前変更


[root@ip-10-150-183-203 cookbooks]# ls
README.md  WebLogic  coherence_inst_1
[root@ip-10-150-183-203 cookbooks]# mv coherence_inst_1 coherence
[root@ip-10-150-183-203 cookbooks]#
[root@ip-10-150-183-203 cookbooks]# cd coherence/
[root@ip-10-150-183-203 coherence]# ls
README.rdoc  definitions  libraries    providers  resources
attributes   files        metadata.rb  recipes    templates
[root@ip-10-150-183-203 coherence]# cd ..
[root@ip-10-150-183-203 cookbooks]# knife cookbook upload coherence
Uploading coherence             [0.0.1]
upload complete
[root@ip-10-150-183-203 cookbooks]# knife node list
  demo.example.net2
  ip-10-146-7-97.ap-northeast-1.compute.internal
[root@ip-10-150-183-203 cookbooks]# knife node show demo.example.net2
Node Name:   demo.example.net2
Environment: _default
FQDN:       
IP:         
Run List:    recipe[coherence_inst_1], recipe[WebLogic::install_10.3.5]
Roles:
Recipes      coherence_inst_1
Platform:    centos 5.5
[root@ip-10-150-183-203 cookbooks]#

[root@ip-10-150-183-203 cookbooks]# knife node run_list remove demo.example.net2 recipe[coherence_inst_1]
run_list:  recipe[WebLogic::install_10.3.5]
[root@ip-10-150-183-203 cookbooks]#
[root@ip-10-150-183-203 cookbooks]# knife node run_list add demo.example.net2 recipe[coherence]
run_list:
    recipe[WebLogic::install_10.3.5]
    recipe[coherence]
[root@ip-10-150-183-203 cookbooks]#



recipeはdefault.rbを使用していたがインストール専用のrecipeを作成する。

[root@ip-10-150-183-203 cookbooks]# ls
README.md  WebLogic  coherence
[root@ip-10-150-183-203 cookbooks]# cd coherence/
[root@ip-10-150-183-203 coherence]# ls
README.rdoc  definitions  libraries    providers  resources
attributes   files        metadata.rb  recipes    templates
[root@ip-10-150-183-203 coherence]# cd recipes/
[root@ip-10-150-183-203 recipes]# ls
default.rb
[root@ip-10-150-183-203 recipes]# cp default.rb install_3.7.0.rb
[root@ip-10-150-183-203 recipes]# ls
default.rb  install_3.7.0.rb
[root@ip-10-150-183-203 recipes]# vi default.rb
[root@ip-10-150-183-203 recipes]# cat default.rb
#
# Cookbook Name:: coherence_inst_1
# Recipe:: default
#
# Copyright 2011, YOUR_COMPANY_NAME
#
# All rights reserved - Do Not Redistribute
#


[root@ip-10-150-183-203 recipes]# cat install_3.7.0.rb
#
# Cookbook Name:: coherence_inst_1
# Recipe:: default
#
# Copyright 2011, YOUR_COMPANY_NAME
#
# All rights reserved - Do Not Redistribute
#

execute "download_coherence" do
  command "s3cmd get 1-1-16-1019:coherence-java-3.7.0.0b23397.zip coherence.zip"
  creates "/home/s3sync/coherence.zip"
  action :run
end

execute "unzip_coherence.zip" do
  command "unzip /home/s3sync/coherence.zip"
  cwd "/root"
  action :run
end

[root@ip-10-150-183-203 recipes]#


既にcoherenceがインストールされている場合に、chef runしたときに再度インストールしないようにする。
下のように、executeリソースのcreatesに、ファイルを指定した場合、そのファイルが存在すれば、executeがスキップされる仕組みを利用する。

[root@ip-10-150-183-203 recipes]# vi default.rb
[root@ip-10-150-183-203 recipes]# cat default.rb
#
# Cookbook Name:: coherence_inst_1
# Recipe:: default
#
# Copyright 2011, YOUR_COMPANY_NAME
#
# All rights reserved - Do Not Redistribute
#


[root@ip-10-150-183-203 recipes]# cat install_3.7.0.rb
#
# Cookbook Name:: coherence_inst_1
# Recipe:: default
#
# Copyright 2011, YOUR_COMPANY_NAME
#
# All rights reserved - Do Not Redistribute
#

execute "download_coherence" do
  command "s3cmd get 1-1-16-1019:coherence-java-3.7.0.0b23397.zip coherence.zip"
  creates "/home/s3sync/coherence.zip"
  action :run
end

execute "unzip_coherence.zip" do
  command "unzip /home/s3sync/coherence.zip"
  cwd "/root"
  action :run
end



最後にuploadするのを忘れずに。
[root@ip-10-150-183-203 recipes]# knife cookbook upload coherence
Uploading coherence             [0.0.1]
upload complete

0 件のコメント:

コメントを投稿