はじめに
第1回の記事では、Cygwinおよび、rbenv環境を構築しました。第2回は、前回構築した環境に仮想化ソフトウエアを導入し、プロビジョニングの核となるChef環境を構築します。
仮想化ソフトウエアの導入
本ブログでは、VirtualBoxの導入からOSインストールまでのチュートリアル解説の中で、VirtualBoxの導入方法について解説していますので、今回は割愛します。
今回インストールするソフトウエアは、下記のとおりです。
ソフトウエア | バージョン |
---|---|
Veewee | 0.3.12 |
Packer | v0.3.11 |
Vagrant | 1.2.7 |
以下の手順でインストールします。
-
posix-spawnのインストール
posix-spawnは、Veeweeのビルドに必要なパッケージです。
以下のコマンドを実行して、インストールします。$ mkdir -p ~/work && cd ~/work $ git clone https://github.com/rtomayko/posix-spawn.git posix-spawn && cd posix-spawn $ gem build posix-spawn.gemspec $ gem i --local posix-spawn-0.3.7.gem --no-ri --no-rdoc
punio@PAPA ~ $ mkdir -p ~/work && cd ~/work punio@PAPA ~/work $ git clone https://github.com/rtomayko/posix-spawn.git posix-spawn && cd posix-spawn Cloning into 'posix-spawn'... remote: Counting objects: 926, done. remote: Compressing objects: 100% (562/562), done. remote: Total 926 (delta 387), reused 744 (delta 303) Receiving objects: 100% (926/926), 172.28 KiB | 167 KiB/s, done. Resolving deltas: 100% (387/387), done. punio@PAPA ~/work/posix-spawn $ gem build posix-spawn.gemspec WARNING: licenses is empty Successfully built RubyGem Name: posix-spawn Version: 0.3.7 File: posix-spawn-0.3.7.gem punio@PAPA ~/work/posix-spawn $ gem i --local posix-spawn-0.3.7.gem --no-ri --no-rdoc DL is deprecated, please use Fiddle Building native extensions. This could take a while... Successfully installed posix-spawn-0.3.7 1 gem installed
-
Veeweeのインストール
仮想マシン自動作成ソフトウエアのVeeweeを、gemパッケージからインストールします。
以下のコマンドを実行して、インストールします。$ gem i veewee --no-ri --no-rdoc
punio@PAPA ~/work/posix-spawn $ gem i veewee --no-ri --no-rdoc DL is deprecated, please use Fiddle Fetching: net-ssh-2.7.0.gem (100%) Successfully installed net-ssh-2.7.0 Fetching: Platform-0.4.0.gem (100%) Successfully installed Platform-0.4.0 Fetching: open4-1.3.0.gem (100%) Successfully installed open4-1.3.0 Fetching: popen4-0.1.2.gem (100%) Successfully installed popen4-0.1.2 Fetching: thor-0.18.1.gem (100%) Successfully installed thor-0.18.1 Fetching: highline-1.6.20.gem (100%) Successfully installed highline-1.6.20 Fetching: progressbar-0.21.0.gem (100%) Successfully installed progressbar-0.21.0 Fetching: i18n-0.6.5.gem (100%) Successfully installed i18n-0.6.5 Fetching: ansi-1.3.0.gem (100%) Successfully installed ansi-1.3.0 Fetching: ruby-vnc-1.0.1.gem (100%) Successfully installed ruby-vnc-1.0.1 Fetching: builder-3.2.2.gem (100%) Successfully installed builder-3.2.2 Fetching: excon-0.28.0.gem (100%) Successfully installed excon-0.28.0 Fetching: formatador-0.2.4.gem (100%) Successfully installed formatador-0.2.4 Fetching: multi_json-1.8.2.gem (100%) Successfully installed multi_json-1.8.2 Fetching: mime-types-1.25.gem (100%) Successfully installed mime-types-1.25 Fetching: net-scp-1.1.2.gem (100%) Successfully installed net-scp-1.1.2 Fetching: mini_portile-0.5.2.gem (100%) Successfully installed mini_portile-0.5.2 Fetching: nokogiri-1.6.0.gem (100%) Building native extensions. This could take a while... Successfully installed nokogiri-1.6.0 Fetching: ruby-hmac-0.4.0.gem (100%) Successfully installed ruby-hmac-0.4.0 Fetching: fog-1.18.0.gem (100%) Successfully installed fog-1.18.0 Fetching: ffi-1.9.3.gem (100%) Building native extensions. This could take a while... Successfully installed ffi-1.9.3 Fetching: childprocess-0.3.9.gem (100%) Successfully installed childprocess-0.3.9 Fetching: diff-lcs-1.2.5.gem (100%) Successfully installed diff-lcs-1.2.5 Fetching: grit-2.5.0.gem (100%) Successfully installed grit-2.5.0 Fetching: libxml-ruby-2.7.0.gem (100%) Building native extensions. This could take a while... Successfully installed libxml-ruby-2.7.0 Fetching: CFPropertyList-2.0.17.gem (100%) Successfully installed CFPropertyList-2.0.17 Fetching: fission-0.4.0.gem (100%) Successfully installed fission-0.4.0 Fetching: os-0.9.6.gem (100%) Successfully installed os-0.9.6 Fetching: veewee-0.3.12.gem (100%) Successfully installed veewee-0.3.12 29 gems installed
-
Packerのインストール
仮想マシン自動作成ソフトウエアのPackerを、ビルド済みパッケージからインストールします。
以下のコマンドを実行して、インストールします。$ mkdir -p ~/sbin && cd ~/sbin $ curl -Lo 0.3.11_windows_386.zip https://dl.bintray.com/mitchellh/packer/0.3.11_windows_386.zip $ unzip -q 0.3.11_windows_386.zip $ rm -f 0.3.11_windows_386.zip
punio@PAPA ~/work/posix-spawn $ mkdir -p ~/sbin && cd ~/sbin punio@PAPA ~/sbin $ curl -Lo 0.3.11_windows_386.zip https://dl.bintray.com/mitchellh/packer/0.3.11_windows_386.zip % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 100 41.9M 100 41.9M 0 0 5502k 0 0:00:07 0:00:07 --:--:-- 4169k punio@PAPA ~/sbin $ unzip -q 0.3.11_windows_386.zip punio@PAPA ~/sbin $ rm -f 0.3.11_windows_386.zip punio@PAPA ~/sbin $ ls packer.exe* packer-command-inspect.exe* packer-builder-amazon-chroot.exe* packer-command-validate.exe* packer-builder-amazon-ebs.exe* packer-post-processor-vagrant.exe* packer-builder-amazon-instance.exe* packer-provisioner-ansible-local.exe* packer-builder-digitalocean.exe* packer-provisioner-chef-solo.exe* packer-builder-openstack.exe* packer-provisioner-file.exe* packer-builder-virtualbox.exe* packer-provisioner-puppet-masterless.exe* packer-builder-vmware.exe* packer-provisioner-salt-masterless.exe* packer-command-build.exe* packer-provisioner-shell.exe* packer-command-fix.exe*
-
Vagrantのインストール
仮想マシンプロビジョニングソフトウエアのVagrantのWindows用インストーラーを、公式サイトからダウンロードしてインストールします。
今回は、Vagrant-1.2.7をインストールします。
なお、既にVagrantがインストール済みの場合、一旦アンインストールしてインストーラーを起動します。インストール済みの場合、インストールができませんので注意して下さい。
インストーラーが起動したら、ウィザードの指示どおりにデフォルトインストールします。
デフォルトでは、C:\HashiCorp\Vagrantにインストールされます。 -
PATH設定
インストールされた仮想化ソフトウエアのPATHを設定します。
~/.bashrcに下記の内容を追加します。export PATH=~/sbin:$PATH # for Packer export PATH=/cygdrive/c/HashiCorp/Vagrant/bin:$PATH # for Vagrant export PATH=/cygdrive/c/Program\ Files/Oracle/VirtualBox:$PATH # for VirtualBox
編集が終了したら、以下のコマンドを実行します。
$ source ~/.bashrc
PATHを表示すると、下記のようになります。
$ echo $PATH /cygdrive/c/Program Files/Oracle/VirtualBox:/cygdrive/c/HashiCorp/Vagrant/bin:/home/punio/sbin:/home/punio/.rbenv/shims:/home/punio/.rbenv/bin:/usr/bin:/usr/sbin
-
バージョン確認
以下のコマンドを実行して、仮想化ソフトウエアのバージョンを確認します。
$ packer -v && vagrant -v && veewee version && vboxmanage -v
punio@PAPA ~/sbin $ packer -v && vagrant -v && veewee version && vboxmanage -v Packer v0.3.11 Vagrant version 1.2.7 Version : 0.3.12 - use at your own risk 4.2.18r88780
Chef環境の構築
ここまでの作業で、プロビジョニング環境の構築のための準備が終了しましたので、核となるChefパッケージをインストールします。
以下の手順でインストールします。
-
chef、knife-solo、berkshelfのインストール
以下のコマンドを実行して、プロビジョニングソフトウエアをgemパッケージからインストールします。
$ gem i chef --no-ri --no-rdoc $ gem i knife-solo --no-ri --no-rdoc $ gem i berkshelf --no-ri --no-rdoc
$ gem i chef --no-ri --no-rdoc DL is deprecated, please use Fiddle Fetching: mixlib-config-2.0.0.gem (100%) Successfully installed mixlib-config-2.0.0 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%) 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.20.0.gem (100%) Successfully installed ohai-6.20.0 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: erubis-2.7.0.gem (100%) Successfully installed erubis-2.7.0 Fetching: hashie-2.0.5.gem (100%) Successfully installed hashie-2.0.5 Fetching: moneta-0.6.0.gem (100%) Successfully installed moneta-0.6.0 Fetching: rack-1.5.2.gem (100%) Successfully installed rack-1.5.2 Fetching: chef-zero-1.7.1.gem (100%) Successfully installed chef-zero-1.7.1 Fetching: puma-1.6.3.gem (100%) Building native extensions. This could take a while... Successfully installed puma-1.6.3 Fetching: coderay-1.1.0.gem (100%) Successfully installed coderay-1.1.0 Fetching: slop-3.4.7.gem (100%) Successfully installed slop-3.4.7 Fetching: method_source-0.8.2.gem (100%) Successfully installed method_source-0.8.2 Fetching: pry-0.9.12.3.gem (100%) Successfully installed pry-0.9.12.3 Fetching: chef-11.8.0.gem (100%) Successfully installed chef-11.8.0 23 gems installed
punio@PAPA ~ $ gem i knife-solo --no-ri --no-rdoc DL is deprecated, please use Fiddle Fetching: knife-solo-0.4.0.gem (100%) Thanks for installing knife-solo! If you run into any issues please let us know at: https://github.com/matschaffer/knife-solo/issues If you are upgrading knife-solo please uninstall any old versions by running `gem clean knife-solo` to avoid any errors. See http://bit.ly/CHEF-3255 for more information on the knife bug that causes this. Successfully installed knife-solo-0.4.0 1 gem installed
$ gem i berkshelf --no-ri --no-rdoc DL is deprecated, please use Fiddle Fetching: activesupport-3.2.15.gem (100%) Successfully installed activesupport-3.2.15 Fetching: addressable-2.3.5.gem (100%) Successfully installed addressable-2.3.5 Fetching: buff-ruby_engine-0.1.0.gem (100%) Successfully installed buff-ruby_engine-0.1.0 Fetching: buff-shell_out-0.1.1.gem (100%) Successfully installed buff-shell_out-0.1.1 Fetching: chozo-0.6.1.gem (100%) Successfully installed chozo-0.6.1 Fetching: multipart-post-1.2.0.gem (100%) Successfully installed multipart-post-1.2.0 Fetching: faraday-0.8.8.gem (100%) Successfully installed faraday-0.8.8 Fetching: minitar-0.5.4.gem (100%) Successfully installed minitar-0.5.4 Fetching: retryable-1.3.3.gem (100%) Successfully installed retryable-1.3.3 Fetching: buff-extensions-0.5.0.gem (100%) Successfully installed buff-extensions-0.5.0 Fetching: varia_model-0.2.0.gem (100%) Successfully installed varia_model-0.2.0 Fetching: buff-config-0.4.0.gem (100%) Successfully installed buff-config-0.4.0 Fetching: buff-ignore-1.1.0.gem (100%) Successfully installed buff-ignore-1.1.0 Fetching: timers-1.1.0.gem (100%) Successfully installed timers-1.1.0 Fetching: celluloid-0.14.1.gem (100%) Successfully installed celluloid-0.14.1 Fetching: nio4r-0.5.0.gem (100%) Building native extensions. This could take a while... Successfully installed nio4r-0.5.0 Fetching: celluloid-io-0.14.1.gem (100%) Successfully installed celluloid-io-0.14.1 Fetching: net-http-persistent-2.9.gem (100%) Successfully installed net-http-persistent-2.9 Fetching: solve-0.8.1.gem (100%) Successfully installed solve-0.8.1 Fetching: gssapi-1.0.3.gem (100%) Successfully installed gssapi-1.0.3 Fetching: httpclient-2.3.4.1.gem (100%) Successfully installed httpclient-2.3.4.1 Fetching: rubyntlm-0.1.1.gem (100%) Successfully installed rubyntlm-0.1.1 Fetching: uuidtools-2.1.4.gem (100%) Successfully installed uuidtools-2.1.4 Fetching: nori-1.1.5.gem (100%) Successfully installed nori-1.1.5 Fetching: httpi-0.9.7.gem (100%) Successfully installed httpi-0.9.7 Fetching: wasabi-1.0.0.gem (100%) Successfully installed wasabi-1.0.0 Fetching: gyoku-1.1.0.gem (100%) Successfully installed gyoku-1.1.0 Fetching: akami-1.2.0.gem (100%) Successfully installed akami-1.2.0 Fetching: savon-0.9.5.gem (100%) Successfully installed savon-0.9.5 Fetching: little-plugger-1.1.3.gem (100%) Successfully installed little-plugger-1.1.3 Fetching: logging-1.8.1.gem (100%) Successfully installed logging-1.8.1 Fetching: winrm-1.1.3.gem (100%) Successfully installed winrm-1.1.3 Fetching: ridley-1.5.3.gem (100%) Successfully installed ridley-1.5.3 Fetching: rbzip2-0.2.0.gem (100%) Successfully installed rbzip2-0.2.0 Fetching: berkshelf-2.0.10.gem (100%) Successfully installed berkshelf-2.0.10 35 gems installed
-
バージョン確認
以下のコマンドを実行して、プロビジョニングソフトウエアのバージョンを確認します。
$ chef-solo -v && knife -v && berks -v
punio@PAPA ~ $ chef-solo -v && knife -v && berks -v DL is deprecated, please use Fiddle Chef: 11.8.0 Chef: 11.8.0 DL is deprecated, please use Fiddle Berkshelf (2.0.10) Copyright 2012-2013 Riot Games Jamie Winsor () Josiah Kiehl () Michael Ivey () Justin Campbell () Seth Vargo () Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
-
knifeの初期化
以下のコマンドを実行して、knifeの初期化を行います。
$ knife configure
初期化すると、~/.chefフォルダが作成され~/.chef/knife.rbが作成されます。
punio@PAPA ~ $ knife configure WARNING: No knife configuration file found Where should I put the config file? [/home/punio/.chef/knife.rb] Please enter the chef server URL: [https://localhost:443] Please enter an existing username or clientname for the API: [punio] 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/punio/.chef/punio.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/punio/.chef/knife.rb
-
Cookbookリポジトリの作成
以下のコマンドを実行して、プロビジョニングに必要となるCookbookリポジトリを作成します。
$ knife solo init ~/chef-repo && cd ~/chef-repo
punio@PAPA ~ $ knife solo init ~/chef-repo && cd ~/chef-repo Creating kitchen... Creating knife.rb in kitchen... Creating cupboards... DL is deprecated, please use Fiddle Setting up Berkshelf...
以降の作業は、すべてchef-repoフォルダで行いますので、注意して下さい。
-
berkshelfの初期化
berkshelfは、OPSCODE Commnityが公開しているCookbookをインストールする際に利用します。
公開Cookbookのダウンロードには、OPSCODE Commnityへの事前登録が必要となります。また、登録時に認証鍵をダウンロードできますので、未登録の方は、Chef Soloを使った仮想マシンのプロビジョニングの方法を参考にして登録して下さい。
以下のコマンドを実行して、berkshelfを初期化します。$ berks init
punio@PAPA ~/chef-repo $ berks init DL is deprecated, please use Fiddle identical Berksfile create Thorfile conflict .gitignore Overwrite /home/punio/chef-repo/.gitignore? (enter "h" for help) [Ynaqdh] Y force .gitignore run git init from "." create Gemfile create Vagrantfile Successfully initialized
実行すると、.gitignoreを上書きするかを確認されますので、Yを入力して上書きします。
-
Cookbook検索パスの設定
プロビジョニング時に利用するCookbookの検索パスを、~/.chef/knife.rbに設定します。
~/.chef/knife.rbに下記の内容を追加します。cookbook_path [ '/home/punio/chef-repo/site-cookbooks', '/home/punio/chef-repo/cookbooks' ]
-
client_keyの設定
OPSCODE Commnityへユーザー登録すると、PEM形式のクライアント認証鍵が取得できますので、取得した認証鍵を~/.chefフォルダにコピーします。
その際には、~/.chef/knife.rb中のclient_keyに指定されたファイル名でコピーして下さい。
今回は、事前に取得しておいた認証鍵をコピーしています。$ cp ~/opscode-key.pem ~/.chef/punio.pem
まとめ
ここまで、仮想化ソフトウエアの導入からchef環境の構築方法について、解説しました。第3回は、今回構築した環境で仮想マシンを作成し、プロビジョニングを行います。