chef -soloを試してみた
準備から実行までのコマンドと出力結果のメモ
- rubyインストール
$ curl -L https://get.rvm.io | bash -s stable --autolibs=enabled $ rvm install ruby $ gem update --system
- chefインストール
$ gem install chef $ gem install knife-solo
- knife初期設定(全部Enter)
$ knife configure
WARNING: No knife configuration file found Where should I put the config file? [/home/takamatu/.chef/knife.rb] Please enter the chef server URL: [https://black:443] Please enter an existing username or clientname for the API: [takamatu] Please enter the validation clientname: [chef-validator] Please enter the location of the validation key: [/etc/chef-server/chef-validator.pem] Please enter the path to a chef repository (or leave blank): ***** You must place your client key in: /home/takamatu/.chef/takamatu.pem Before running commands with Knife! ***** You must place your validation key in: /etc/chef-server/chef-validator.pem Before generating instance data with Knife! ***** Configuration file written to /home/takamatu/.chef/knife.rb
- chefリポジトリ作成
$ cd ~/git
$ knife solo init chef-repo
Creating kitchen... Creating knife.rb in kitchen... Creating cupboards...
$ cd chef-repo
$ git init
Initialized empty Git repository in /home/takamatu/git/chef-repo/.git/
$ git add . $ git commit -m "INIT"
[master (root-commit) 471c734] INIT 2 files changed, 9 insertions(+) create mode 100644 .chef/knife.rb create mode 100644 .gitignore create mode 100644 data_bags/.gitkeep create mode 100644 environments/.gitkeep create mode 100644 nodes/.gitkeep create mode 100644 roles/.gitkeep create mode 100644 site-cookbooks/.gitkeep
- 管理対象サーバにchefをインストール(brownが管理対象サーバ名)
$ knife solo prepare brown
Bootstrapping Chef... Enter the password for takamatu@brown: 【サーバ側でsudo実行時に入力するパスワード】 % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 6790 100 6790 0 0 3944 0 0:00:01 0:00:01 --:--:-- 3945 Downloading Chef 11.8.0 for ubuntu... Installing Chef 11.8.0 以前に未選択のパッケージ chef を選択しています。 (データベースを読み込んでいます ... 現在 247047 個のファイルとディレクトリがインストールされています。) (.../chef_11.8.0_i386.deb から) chef を展開しています... chef (11.8.0-1.ubuntu.13.04) を設定しています ... Thank you for installing Chef! Generating node config 'nodes/brown.json'...
$ git add . $ git commit -m "add node brown"
[master 87f2f69] add node brown 1 file changed, 1 insertion(+) create mode 100644 nodes/brown.json
- クックブック作成
$ knife cookbook create dev -o site-cookbooks
** Creating cookbook dev ** Creating README for cookbook: dev ** Creating CHANGELOG for cookbook: dev ** Creating metadata for cookbook: dev
- レシピ作成
$ vi site-cookbooks/dev/recipes/default.rb
# # Cookbook Name:: dev # Recipe:: default # # Copyright 2013, YOUR_COMPANY_NAME # # All rights reserved - Do Not Redistribute # log "基本設定" %w{tmux vim}.each do |pkg| package pkg do action :install end end # vim: ts=2 sw=2 et:
$ git add . $ git commit -m "add cookbook & recipe"
[master c2e720c] add cookbook 4 files changed, 104 insertions(+) create mode 100644 site-cookbooks/dev/CHANGELOG.md create mode 100644 site-cookbooks/dev/README.md create mode 100644 site-cookbooks/dev/metadata.rb create mode 100644 site-cookbooks/dev/recipes/default.rb
- レシピをノードに割り当て
$ vi nodes/brown.json
{ "run_list":[ "recipe[dev]" ] } // vim: set ts=4 sw=4 et:
$ git add . $ git commit -m "assign dev to brown"
[master 999c421] assign dev to brown 1 file changed, 6 insertions(+), 1 deletion(-)
- 管理対象サーバにレシピを適用
$ knife solo cook brown
Running Chef on brown... Checking Chef version... Enter the password for takamatu@brown: 【サーバ側でsudo実行時に入力するパスワード】 Uploading the kitchen... Generating solo config... Running Chef... Starting Chef Client, version 11.8.0 Compiling Cookbooks... Converging 3 resources Recipe: dev::default * log[基本設定] action write * package[tmux] action install (up to date) * package[vim] action install (up to date) Chef Client finished, 1 resources updated
参考
入門Chef Solo - Infrastructure as Code
- 作者: 伊藤直也
- 出版社/メーカー: 伊藤直也
- 発売日: 2013/03/11
- メディア: Kindle版
- 購入: 16人 クリック: 1,027回
- この商品を含むブログ (14件) を見る