SSブログ

Cehf-soloとKnife-soloをセットアップする [Chef]

Chef-soloをインストールする


Chef-soloのインストールには、いろいろ方法があります。
おそらく、http://ch.nicovideo.jp/dwango-engineer/blomaga/ar322283あたりの情報が正しいのだろうと思います。
しかし、今回、gemインストールする方法でインストールしたので、その手順以下を記載します。

Chef-soloを以下のコマンドでインストールします。
C:\Users\hoge> gem install chef Fetching: mixlib-config-1.1.2.gem (100%) Successfully installed mixlib-config-1.1.2 Fetching: mixlib-cli-1.3.0.gem (100%) Successfully installed mixlib-cli-1.3.0 Fetching: mixlib-log-1.6.0.gem (100%) Successfully installed mixlib-log-1.6.0 Fetching: mixlib-authentication-1.3.0.gem (100%) Successfully installed mixlib-authentication-1.3.0 Fetching: mixlib-shellout-1.2.0.gem (100%) Successfully installed mixlib-shellout-1.2.0 Fetching: systemu-2.5.2.gem (100%) Successfully installed systemu-2.5.2 Fetching: yajl-ruby-1.1.0.gem (100%) Temporarily enhancing PATH to include DevKit... Building native extensions. This could take a while... Successfully installed yajl-ruby-1.1.0 Fetching: ipaddress-0.8.0.gem (100%) Successfully installed ipaddress-0.8.0 Fetching: ohai-6.18.0.gem (100%) Successfully installed ohai-6.18.0 Fetching: mime-types-1.25.gem (100%) Successfully installed mime-types-1.25 Fetching: rest-client-1.6.7.gem (100%) Successfully installed rest-client-1.6.7 Fetching: net-ssh-gateway-1.2.0.gem (100%) Successfully installed net-ssh-gateway-1.2.0 Fetching: net-ssh-multi-1.1.gem (100%) Successfully installed net-ssh-multi-1.1 Fetching: highline-1.6.19.gem (100%) Successfully installed highline-1.6.19 Fetching: chef-11.6.0.gem (100%) Successfully installed chef-11.6.0 Parsing documentation for mixlib-config-1.1.2 Installing ri documentation for mixlib-config-1.1.2 Parsing documentation for mixlib-cli-1.3.0 Installing ri documentation for mixlib-cli-1.3.0 Parsing documentation for mixlib-log-1.6.0 Installing ri documentation for mixlib-log-1.6.0 Parsing documentation for mixlib-authentication-1.3.0 Installing ri documentation for mixlib-authentication-1.3.0 Parsing documentation for mixlib-shellout-1.2.0 Installing ri documentation for mixlib-shellout-1.2.0 Parsing documentation for systemu-2.5.2 Installing ri documentation for systemu-2.5.2 Parsing documentation for yajl-ruby-1.1.0 unable to convert "\x90" from ASCII-8BIT to UTF-8 for lib/yajl/yajl.so, skipping Installing ri documentation for yajl-ruby-1.1.0 Parsing documentation for ipaddress-0.8.0 Installing ri documentation for ipaddress-0.8.0 Parsing documentation for ohai-6.18.0 Installing ri documentation for ohai-6.18.0 Parsing documentation for mime-types-1.25 Installing ri documentation for mime-types-1.25 Parsing documentation for rest-client-1.6.7 Installing ri documentation for rest-client-1.6.7 Parsing documentation for net-ssh-gateway-1.2.0 Installing ri documentation for net-ssh-gateway-1.2.0 Parsing documentation for net-ssh-multi-1.1 Installing ri documentation for net-ssh-multi-1.1 Parsing documentation for highline-1.6.19 Installing ri documentation for highline-1.6.19 Parsing documentation for chef-11.6.0 Installing ri documentation for chef-11.6.0 15 gems installed

Windows環境用(64bit版)には、以下のgemも必要なので、順次インストールしておきます。
C:\Users\hoge> gem install win32-process windows-pr win32-open3 ruby-wmi windows-api rdp-ruby-wmi win32-service --no-ri --no-rdoc

以下のコマンドを実行してバージョンが表示されれば、OKです。
C:\Users\hoge> chef-solo --version DL is deprecated, please use Fiddle Chef: 11.6.0

※「DL is deprecated, please use Fiddle」は、コマンドを実行するたびに表示されますが、実行には問題ないので、放置しておきます。

ローカル環境からリモートのChef-soloを操作するための、knife-soloをインストールします。
C:\Users\hoge>gem install knife-solo Fetching: knife-solo-0.3.0.gem (100%) Thanks for installing knife-solo! C:\Users\hoge> gem install knife-solo -v 0.3.0.pre5 --pre

※0.3.0と0.3.0-pre5の両方をいれないと、knife soloコマンドが動かない・・・。(なぜだろう?)

Chefの環境設定ファイルの作成とリポジトリ作成を行います。
C:\Users\hoge> knife configure C:\Users\hoge> knife solo init chef-repo Creating kitchen... Creating knife.rb in kitchen... Creating cupboards...

ゲストOSにChef-soloをインストールする


knifeコマンドでインストールできます。
knifeコマンド実行時に、wget/curlを使用してChef-soloをダウンロードするので、プロキシ環境の場合は、以下の設定を行います。
【/etc/environment】
export http_proxy=http://proxy.xxxxxx.xx.xx:8080/ export https_proxy=http://proxy.xxxxxx.xx.xx:8080/

knifeコマンドの実行は、以下の通りです。
C:\Users\hoge> knife solo prepare vagrant@192.168.56.201 -P vagrant DL is deprecated, please use Fiddle Bootstrapping Chef... % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 101 6790 101 6790 0 0 1149 0 0:00:05 0:00:05 --:--:-- 9288 Downloading Chef 11.6.0 for el... Installing Chef 11.6.0 warning: /tmp/tmp.4MTbRPlV/chef-11.6.0.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 83ef826a: NOKEY Preparing... ########################################### [100%] package chef-11.6.0-1.el6.x86_64 is already installed

Rsyncを用意する


Windows環境には、Rsyncコマンドは用意されていませんが、knife soloコマンドが必須で使用するので、cwRsyncを導入します。

以下のURLからFreeの最新版(この時点では、4.0.5)のcwRsyncをダウンロードする。zipファイルが入手できるので、解凍して作成されたファイルを実行します。
https://www.itefix.no/i2/content/cwrsync-free-edition

vagrantで作成したCentOS 6.4には、rsyncコマンドが導入されていないので、yumにて導入しておきます。(本末転倒ですが・・・・)その際には、必要に応じて、プロキシの設定をおこなっておきます。
vagrant:$ sudo --s # export http_proxy=http://proxy.xxxxxx.xx.xx:8080/ # yum install rsync

Knife-soloの動作確認を行う


動作確認として、knife soloコマンドで「Hello World!」を表示してみます。

Chefリポジトリのディレクトリをカレントディレクトリにします。
C:\Users\hoge>cd chef-repo


まずは、リポジトリに「Hello World」用のCookbookを作成します。
C:\Users\hoge\chef-repo> knife cookbook create hello -o site-cookbooks

ファイルの内容:
# # Cookbook Name:: hello # Recipe:: default # # Copyright 2013,xxx # # All rights reserved - Do Not Redistribute # log "Hello World!"

実行するコマンドを指定するJSONファイルを記述します。JSONファイルのファイル名は、ホスト名.jsonです。ここでは、以下のファイルです。
C:\Users\hoge\chef-repo\nodes\hoge201.json

ファイルの記述内容:
// hoge201.json { "run_list" : [ "recipe[hello]" ] }

※ホスト名は、knife soloコマンド実行時に指定するホスト名であり、hostsファイルに記述されていればかまいません。(C:\windows\system32\drivers\hosts)hostsファイルは管理者権限がないと変更できないので注意すること。)

knife-soloコマンドで「Hello World」を実行します。(以下、すべてこのコマンドだけでOKである)
C:\Users\hoge\chef-repo> knife solo cook vagrant@hoge201


参考URL:
https://www.itefix.no/i2/content/cwrsync-free-edition
https://www.itefix.no/i2/content/cwrsync-free-edition

タグ:Chef

共通テーマ:blog

この広告は前回の更新から一定期間経過したブログに表示されています。更新すると自動で解除されます。