LoginSignup
10
10

More than 5 years have passed since last update.

VagrantとChef Soloをかじる

Posted at

ずっと手を出したかったVagrantとChef。
チュートリアルhttp://qiita.com/taiki45/items/b46a2f32248720ec2baeの履歴メモ。

Virtual Box 入れた

Vagrant入れた(gemだとバージョン古いらしいのでdownload)

vagrant -v
Vagrant 1.3.5

出た。

Vagrant用のテストディレクトリつくる

Box(テンプレート)とってくる

vagrant init "Debian7" "https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_debian-7.1.0_provisionerless.box"
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.

とか、Vagrantbox.esから

vagrant box add centos64 http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.4-x86_64-v20130427.box

とかで。

Box(テンプレート)一覧を見る

vagrant box list
Debian7  (virtualbox)
centos64 (virtualbox)

設定ファイルのぞいてみる

設定ファイルVagrantfile

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "Debian7"
  config.vm.box_url = "https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_debian-7.1.0_provisionerless.box"
end

さっき設定したやつや。

立ち上げてみる

vagrant up

立ち上がったら入る

vagrant ssh

Shared Folder

ホストのVagrantfileがあるディレクトリと
VM内の/vagrantは共有されている。

Chef Solo

  • Vagrant が VM を立ち上げる
  • Cookbook を VM に転送する
  • VM 上で Chef Solo を実行する

この流れを試す。

vagrant-omnibus

vagrant-berkshelf

vagrant plugin install vagrant-omnibus
vagrant plugin install vagrant-berkshelf

gem install berkself

Berkshelfの設定ファイル

Berkshelfが設定ファイル

site:opscode

site:opscodeとはsource "https://rubygems.orgと同じようなものらしい。特にソースを指定しない場合はopscodeからダウンロードするよっていう意味みたい。

Cookbookの置き場所

置き場所についての作法としては
汎用的な Cookbook を置く場所が cookbooks で、その環境構築固有の Cookbook を site-cookbooks に置くことが多いらしい。

cookbookをberksする。

cd site-cookbooks
berks cookbook hello

hello以下にcookbookのあれそれが自動的に作られる。

hello/recipes/default.rbを編集する

log "Hello World!!!!!!!!!!!!!"

VagrantFileにvagrant-berkshelfプラグインとvagrant-omnibusプラグインの設定を書く

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  # ...
  config.omnibus.chef_version = :latest
  config.berkshelf.enabled = true
  # ...
end

Berksfile helloのcookbookのパスを設定

site :opscode
cookbook "hello", path: "site-cookbooks/hello"

Vagrant upさせる

VagrantFileの中身は最終的にはこんな感じ

# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "Debian7"
  config.vm.box_url = "https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_debian-7.1.0_provisionerless.box"

  config.vm.provision :chef_solo do |chef|
    chef.run_list = ["hello"]
  end

  config.berkshelf.enabled = true
  config.omnibus.chef_version = :latest

end

先ほど作った環境を壊して

vagrant destroy

vagrant upする

vagrant up
[2013-10-20T07:14:28+00:00] INFO: Hello World!!!!!!!!!!!!!
[2013-10-20T07:14:28+00:00] INFO: Chef Run complete in 0.020857476 seconds

出た。

10
10
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
10
10