일요일, 6월 23, 2024
HomeLinuxubuntu chef cookbook 및 recipe 등록

ubuntu chef cookbook 및 recipe 등록

ubuntu chef cookbook 및 recipe 등록

1.Cookbook 과 레시피 코딩

admin@ip-10-2-2-200:~# knife cookbook create HelloWorld
admin@ip-10-2-2-200:/etc/chef-server/chef-repo/cookbooks$ ll
total 16
drwxrwxr-x  3 admin admin 4096 Mar  4 16:35 ./
drwxrwxr-x  8 admin admin 4096 Mar  3 17:45 ../
drwxrwxr-x 10 admin admin 4096 Mar  4 16:35 HelloWorld/
-rw-rw-r--  1 admin admin 3064 Jan  9 13:37 README.md

admin@ip-10-2-2-200:~# vi /etc/chef-server/chef-repo/cookbooks/HelloWorld/attributes/HelloWorld.rb
default['message']='Hello World!!'

admin@ip-10-2-2-200:~# vi /etc/chef-server/chef-repo/cookbooks/HelloWorld/recipes/default.rb
#
# Cookbook Name:: HelloWorld
# Recipe:: default
#
# Copyright 2015, YOUR_COMPANY_NAME
#
# All rights reserved - Do Not Redistribute
#
template "/tmp/HelloWorld.txt" do
        source "HelloWorld.txt.erb"
        variables :message => node['message']
        action :create
end

admin@ip-10-2-2-200:~# vi /etc/chef-server/chef-repo/cookbooks/HelloWorld/templates/default/HelloWorld.txt.erb
My Message is : <%=@message %>

admin@ip-10-2-2-200:~# cd /etc/chef-server/chef-repo/cookbooks
admin@ip-10-2-2-200:/etc/chef-server/chef-repo/cookbooks$ knife cookbook upload -a -o ./
admin@ip-10-2-2-200:/etc/chef-server/chef-repo/cookbooks$ knife cookbook list
HelloWorld   0.1.0 

2. client 에서의 레시피 등록 및 확인

root@ip-10-2-2-20:/etc/chef# cat first-boot.json 
{"run_list":[
"recipe[HelloWorld]"
]}
root@ip-10-2-2-20:/etc/chef# chef-client -j first-boot.json 
Starting Chef Client, version 12.1.0
resolving cookbooks for run list: ["HelloWorld"]
Synchronizing Cookbooks:
  - HelloWorld
Compiling Cookbooks...
Converging 1 resources
Recipe: HelloWorld::default
  * template[/tmp/HelloWorld.txt] action create
    - create new file /tmp/HelloWorld.txt
    - update content in file /tmp/HelloWorld.txt from none to e0c37f
    --- /tmp/HelloWorld.txt     2015-03-04 18:06:50.316981975 +0900
    +++ /tmp/chef-rendered-template20150304-4757-1dypmr2        2015-03-04 18:06:50.316981975 +0900
    @@ -1 +1,2 @@
    +My Message is : Hello World!!

Running handlers:
Running handlers complete
Chef Client finished, 1/1 resources updated in 1.307225431 seconds

3.workstation에서 node 에 recipe 등록 및 확인

admin@ip-10-2-2-200:~$ knife node run_list add ip-10-2-2-20.computer-1.com 'recipe[HelloWorld]'
admin@ip-10-2-2-200:~$ knife ssh 'name:ip-10-2-2-20.computer-1.com' 'sudo chef-client -S https://ip-10-2-2-200.computer-1.com:443 -k /etc/chef/client.pem -c /etc/chef/client.rb -K /etc/chef/validation.pem' -x admin -P password -p 22

4.workstation에서 knife을 이용한 node 에 apt-get update 실행하기

knife ssh 'name:ip-10-2-2-20.computer-1.com' 'sudo apt-get -y update' -x admin -P password -p 22
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Time limit exceeded. Please complete the captcha once again.

Most Popular