chefdk の ローカルインストール
資材はどうしても必要なのでオンラインでダウンロードしたものをサーバに配置する。(今回はwgetしちゃってます)
※「$」でコンソール書いてますけどrootで作業してます(#だとコメントアウトとわかりづらいので)
$ wget https://opscode-omnibus-packages.s3.amazonaws.com/el/6/x86_64/chefdk-0.4.0-1.x86_64.rpm
$ rpm -Uvh chefdk-0.4.0-1.x86_64.rpm
$ chef --version
Chef Development Kit Version: 0.4.0
$ chef generate repo chef-repo
Compiling Cookbooks...
以下略
$ cd chef-repo/
$ vi centos.json
{ "run_list": "recipe[echo]" }
$ knife cookbook create echo -o cookbooks
$ vi cookbooks/echo/recipes/default.rb
#
# Cookbook Name:: echo
# Recipe:: default
#
# Copyright 2015, YOUR_COMPANY_NAME
#
# All rights reserved - Do Not Redistribute
#
script "echo test" do
interpreter "bash"
user "root"
code <<-EOL
echo "ECHOTEST" >> /tmp/echo.log
cat /tmp/echo.log
EOL
end
$ ls -l /tmp/
total 0
$ chef-client -z -j centos.json
[2015-03-03T14:50:21+00:00] WARN: No config file found or specified on command line, using command line options.
Starting Chef Client, version 12.0.3
resolving cookbooks for run list: ["echo"]
Synchronizing Cookbooks:
- echo
Compiling Cookbooks...
Converging 1 resources
Recipe: echo::default
* script[echo test] action run
- execute "bash" "/tmp/chef-script20150303-4755-ydbzl"
Running handlers:
Running handlers complete
Chef Client finished, 1/1 resources updated in 3.085442146 seconds
$ ls -l /tmp/
total 4
-rw-r--r--. 1 root root 9 2015-03-03 14:50 echo.log
$ cat /tmp/echo.log
ECHOTEST
$ ls -l nodes/xxxx.json
$ cat nodes/xxxx.json
以下略
$ knife configure
$ cat /root/.chef/knife.rb
log_level :info
log_location STDOUT
node_name 'root'
client_key '/root/.chef/root.pem'
validation_client_name 'chef-validator'
validation_key '/etc/chef-server/chef-validator.pem'
chef_server_url 'https://xxxx:443'
syntax_check_cache_path '/root/.chef/syntax_check_cache'
$ vi /root/.chef/knife.rb
log_level :info
log_location STDOUT
node_name 'root'
syntax_check_cache_path '/root/.chef/syntax_check_cache'
$ knife node list -z
xxxx
$ knife node show xxxx -z
以下略
$ knife cookbook list -z
echo 0.1.0
参考
・http://www.creationline.com/lab/6380
・http://www.sawanoboly.net/blog/2014/11/25/chef-solo-zero-knife-solo-zero