6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Vagrant+chef-soloの練習

Posted at

#概要
VirtualBox(VMWare)で仮想マシンが作れるのを、更にコマンドで簡単に設定していく (備忘録)

環境・レシピの用意

  • OS X 10.8.4
  • ruby-1.9.3-p392

$gem install chef -- --no-ri --no-rdoc

$knife configure

$gem install knife-solo -- --no-ri --no-rdoc

##cookbook 作成

リポジトリを作って、その中にmycookbookというcookbookを作る

knife solo init myrepo

knife cookbook create mycookbook -o myrepo/site-cookbooks/

  • デフォルトは/var/chef/以下にいろいろ作られる

  • /etc/chef/solo.rb
    => 生まれたてのVagrantVM上で
    chef-solo
    だけ実行すると探していた。

chef-soloをVM上で実行する

  • ゲストで/etc/chef/solo.rb を作成。
  • /vagrant/myrepoをcookbookpathに指定
  • sudo chef-solo -o cookbookname
  • これでとりあえずいける

chef-soloを実行する際に参照するファイル
cookbook作成のファイルパスを指定することなどができる

solo.rb
file_cache_path "/tmp/chef-solo"
cookbook_path ["/vagrant/myrepo/site-cookbooks"]
log_level :debug
/vagrant/myrepo/site-cookbooks/mycookbook/recipes/default.rb
#
# Cookbook Name:: mycookbook
# Recipe:: default
#
# Copyright 2013, YOUR_COMPANY_NAME
#
# All rights reserved - Do Not Redistribute
#

log 'Hello Chef'
package 'httpd' do
	action :install
end

package "postgresql-server" do
	action :install
end

#version_file = "/var/lib/post

##cookbook実行
vagrantで生成したVMにchef-soloでcookbookを流し込むのをしたい

下記のように追加する

config.vm.provision :chef_solo do |chef|
	chef.cookbooks_path = "myrepo/site-cookbooks"
	chef.add_recipe "mycookbook"
	chef.json = {:nameservers => ["10.0.0.1"]}
end

vagrant upですべて正常にいけば終わり

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?