LoginSignup
13
11

More than 5 years have passed since last update.

Chefを使ってみる - 導入編(Windowsに環境準備)

Last updated at Posted at 2014-12-04

概要

Windows7環境にChef-solo、Knifesolo、VirtualBox、VagrantをインストールしてChefを試してみる
なんとなく動くけど、動かないことも多々ある。MacかLinux使ったほうがbetter

※書きながら気づいたけど、Chef Clientのmsi使えばいいんじゃん。。。。orz

メモ

・Chef-Repoを決めておく c:\var\opt\chef\repos
・Chef-RepoにVagrantfileを配置する
・hosts(DNS)とssh/configをうまく利用する(Vagrantやsshするとき便利)

作業の流れ

Ruby/bundlerインストール
 ↓
ssh/rsyncインストール
 ↓
Chef/Knife-Soloインストール
 ↓
VirtualBoxインストール
 ↓
Vagrantインストール

Ruby/Bundlerインストール

  1. RubyInstaller for Windows より最新版のRubyをダウンロードし、インストールする
    Version:1.9.3-p550
    PATH:C:\var\opt\ruby193
    Development KITもインストールしておく

    
    > ruby dk.rb init
    > ruby dk.rb install
    
  2. インストール後、コマンドプロンプトから以下を実行・確認

    
    >ruby -v
    ruby 1.9.3p550 (2014-10-27) [i386-mingw32]
    
  3. Bundlerをインストール

    
    >gem install bundler
    
  4. 不要パッケージ削除

    
    >gem uninstall win32-api
    >gem uninstall chef
    >gem uninstall knife-solo
    
  5. tmpディレクトリを作成し、Gemfileを作成

    
    >mkdir c:\tmp
    >dir
    Gemfile
    >type Gemfile
    source 'https://rubygems.org'
     
    gem "knife-solo"
     
    gem "win32-api", "~> 1.5.1", platforms: [:mingw, :x64_min
     
    # for chef-solo on Windows
    #gem "ruby-wmi", platforms: [:mingw, :x64_mingw]
    #gem "win32-service", platforms: [:mingw, :x64_mingw]
    
  6. bundle install実施

    
    >bundle install
    Fetching gem metadata from https://rubygems.org/..........
    Resolving dependencies...
    Installing erubis 2.7.0
    Installing highline 1.6.21
     
    Gem::InstallError: The 'json' native gem requires installed build tools.
     
    Please update your PATH to include build tools or download the DevKit
    from 'http://rubyinstaller.org/downloads' and follow the instructions
    at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit'
    An error occurred while installing json (1.7.7), and Bundler cannot cont
    Make sure that gem install json -v '1.7.7' succeeds before bundling.
    

sshとrsyncをインストール

  1. MinGW - Minimalist GNU for Windowsからmingwをダウンロードし、インストール
    Version:0.6.2
    PATH:c:\var\opt/MinGW
    ※mysys-openssh (bin)とmsys-rsync (bin)をインストール
    ※~/.ssh/configを作成しておくと便利

    
    >type ~/.ssh/config
    Host 127.0.0.1
    HostName        127.0.0.1
    Port            2222
    IdentityFile    C:\Users\user.vagrant.d\insecure_private_key
    User            vagrant
    
  2. C:\var\opt\MinGW\binとC:\var\opt\MinGW\msys\1.0\binにPATHを通す

  3. C:\var\opt\MinGW\msys\1.0\etc\fstab を以下のように記載

fstab
C:  /cygdrive/c
C:/home /home

Chef/Knife-Soloインストール

  1. Chefをインストール

    
    >gem install chef
    Fetching: libyajl2-1.2.0.gem (100%)
    Temporarily enhancing PATH to include DevKit...
    Building native extensions.  This could take a while...
    Successfully installed libyajl2-1.2.0
    1 gem installed
    Installing ri documentation for libyajl2-1.2.0...
    Installing RDoc documentation for libyajl2-1.2.0...
    
  2. Knife-Soloをインストール

    
    >gem install knife-solo
    
  3. Chef Deployment Kitをインストール

    
    >berks version
    3.2.1
    

VartualBoxをインストール

  1. VirtualBoxより最新版のVirtualBoxをダウンロードし、インストールする Version:4.3.18 PATH:C:\var\opt\VirtualBox

Vagrantをインストール

  1. VagrantbよりVagrantをダウンロードし、インストールする
    Version:1.6.5
    PATH:C:\var\opt\Vagrant

  2. コマンドプロンプトよりバージョン確認

    
    >vagrant -v
    Vagrant 1.6.5
    
13
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
11