vagrantでdebian wheezyの環境を作る

最近仕事でもvagrantを使うのでいろいろ覚えつつ、個人用環境を作ってみた。

vagrantとは

vagrantの使い方やってるページはいろいろあるのでそのへんで

詰まったところ

chefがインストールできない

とりあえず http://www.vagrantbox.es/ からwheezyのvanillaって書いてあるやつを持ってきて入れた。
chefが入ってないので vagrant-omunibusを使う。
ssl的なエラーが出てインストールできない。

# Vagrantfile

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.omnibus.chef_version = :latest
  :
  :
  :
# ログ
Please detail your operating system type, version and any other relevant details
Metadata URL: https://www.opscode.com/chef/metadata?v=11.8.2&prerelease=false&p=debian&pv=6&m=x86_64
\nDEBUG OUTPUT FOLLOWS:\n\nSTDERR from wget:\n\n--2013-12-22 09:14:57--  https://www.opscode.com/chef/metadata?v=11.8.2&prerelease=false&p=debian&pv=6&m=x86_64
Resolving www.opscode.com (www.opscode.com)... 184.106.28.90
Connecting to www.opscode.com (www.opscode.com)|184.106.28.90|:443... connected.
ERROR: The certificate of `www.opscode.com' is not trusted.

opscodeからもってきたレシピがインストールできない

http://www.vagrantbox.es/ からchefが入ってるwheezy(Debian Wheezy 7.1 amd64 (french) with Chef 11.4.4 and VirtualBox 4.1.18)を持ってきて入れた。
適当にmysql::serverとか入れてみるけどapparmor-utilsがどうとかでインストールできない。
ぶっちゃけこのへんの関係が知りたいわけじゃないから原因は調べてない

================================================================================
Error executing action `install` on resource 'package[apparmor-utils]'
================================================================================


Chef::Exceptions::Exec
----------------------
apt-get -q -y install apparmor-utils=2.7.103-4 returned 100, expected 0


Resource Declaration:
---------------------
# In /tmp/vagrant-chef-1/chef-solo-1/cookbooks/mysql/recipes/_server_debian.rb

 28:   package name do
 29:     action :install
 30:   end
 31: end

パッケージのマイナーバージョンが違ってインストールできない

recipe[mysql::server]と書いて実行すると下記のように404になる。

fter this operation, 98.5 MB of additional disk space will be used.
Get:1 http://ftp.us.debian.org/debian/ wheezy/main libaio1 amd64 0.3.109-3 [9,150 B]
Get:2 http://ftp.us.debian.org/debian/ wheezy/main libnet-daemon-perl all 0.48-1 [46.2 kB]
Err http://security.debian.org/ wheezy/updates/main mysql-common all 5.5.31+dfsg-0+wheezy1
  404  Not Found [IP: 200.17.202.197 80]
Get:3 http://ftp.us.debian.org/debian/ wheezy/main libplrpc-perl all 0.2020-2 [36.0 kB]
Get:4 http://ftp.us.debian.org/debian/ wheezy/main libdbi-perl amd64 1.622-1 [898 kB]
Err http://security.debian.org/ wheezy/updates/main libmysqlclient18 amd64 5.5.31+dfsg-0+wheezy1
  404  Not Found [IP: 200.17.202.197 80]
Err http://security.debian.org/ wheezy/updates/main mysql-client-5.5 amd64 5.5.31+dfsg-0+wheezy1
  404  Not Found [IP: 200.17.202.197 80]
Err http://security.debian.org/ wheezy/updates/main mysql-server-core-5.5 amd64 5.5.31+dfsg-0+wheezy1
  404  Not Found [IP: 200.17.202.197 80]
Err http://security.debian.org/ wheezy/updates/main mysql-server-5.5 amd64 5.5.31+dfsg-0+wheezy1

実際にサイトに言ってみると5.5.33しかない。
f:id:kambayashi:20131224001003p:plain

mysqlがdebian7に対応してない

このへんの問題
https://github.com/opscode-cookbooks/mysql/pull/132
下記のようなエラー

Chef::Exceptions::FileNotFound
------------------------------
Cookbook 'mysql' (4.0.14) does not contain a file at any of these locations:
  templates/debian-7.0/init-mysql.conf.erb
  templates/debian/init-mysql.conf.erb
  templates/default/init-mysql.conf.erb

This cookbook _does_ contain: ['/tmp/vagrant-chef-1/chef-solo-1/cookbooks/mysql/templates/default/debian.cnf.erb','/tmp/vagrant-chef-1/chef-solo-1/cookbooks/mysql/templates/default/grants.sql.erb','/tmp/vagrant-chef-1/chef-solo-1/cookbooks/mysql/templates/default/my.cnf.erb','/tmp/vagrant-chef-1/chef-solo-1/cookbooks/mysql/templates/default/mysql-server.seed.erb','/tmp/vagrant-chef-1/chef-solo-1/cookbooks/mysql/templates/default/port_mysql.erb','/tmp/vagrant-chef-1/chef-solo-1/cookbooks/mysql/templates/default/usr.sbin.mysqld.erb','/tmp/vagrant-chef-1/chef-solo-1/cookbooks/mysql/templates/ubuntu-10/init-mysql.conf.erb','/tmp/vagrant-chef-1/chef-solo-1/cookbooks/mysql/templates/ubuntu-12/init-mysql.conf.erb','/tmp/vagrant-chef-1/chef-solo-1/cookbooks/mysql/templates/windows/my.ini.erb']

Resource Declaration:
---------------------
# In /tmp/vagrant-chef-1/chef-solo-1/cookbooks/mysql/recipes/_server_debian.rb

 77: template '/etc/init/mysql.conf' do
 78:   source 'init-mysql.conf.erb'
 79: end

phpiisの部分でどうとかいわれる

下記近辺で定義がない感じのエラーが出る。
このへん
https://github.com/opscode-cookbooks/iis/blob/master/libraries/helper.rb#L29

Relevant File Content:
----------------------
/tmp/vagrant-chef-1/chef-solo-1/cookbooks/iis/libraries/helper.rb:

 23:    require 'chef/win32/version'
 24:  end
 25:
 26:  module Opscode::IIS
 27:    class Helper
 28:
 29:      def self.older_than_windows2008r2?
 30>>       win_version = Chef::ReservedNames::Win32::Version.new

解決方法

opscodeのクックブックの問題かboxファイルの問題かわからなくなるからvanillaに最小限の変更をいれたboxファイルを作ることにした。
まずvanillaをそのまま起動する。

$ vagrant box add debian-wheezy-vanilla https://dl.dropboxusercontent.com/s/xymcvez85i29lym/vagrant-debian-wheezy64.box
$ vagrant init debian-wheezy-vanilla
$ vagrant up

sshでログインしてssl関係のものをインストールする(最初のchefがインストール出来なかった問題用)

mac$ vagrant ssh

vagrant$ sudo apt-get install ca-certificates

ログアウトしてboxファイルを作る

mac$ vagrant package
[default] Attempting graceful shutdown of VM...
[default] Clearing any previously set forwarded ports...
[default] Creating temporary directory for export...
[default] Exporting VM...
[default] Compressing package to: /Users/kambayashia/projects/vagrant-files/test/package.box

作成したboxをvagrantに登録してそれを使うようにする。

Vagrantfileにaptを加えてrun_listにも加える。
これで最初にapt-get updateされる(マイナーバージョンが違って404になる問題用)

# Vagrantfile
     :
     :
    chef.run_list = [
      "recipe[apt::default]",
     :
     :

debian7対応がまだマージされてないので、Berksfileのmysqlをいったん独自リポジトリにする。
下記ブランチ、変更点はコミット履歴で
https://github.com/kambayashia/cookbooks-mysql/tree/debian7

cookbook 'mysql', github: "kambayashia/cookbooks-mysql", branch: "debian7"

phpiisはmetadata.rbにdependsが入ってるから起きてるけど、みんなどうやって解決してるのか知りたい。
https://github.com/opscode-cookbooks/php/blob/master/metadata.rb#L12
とりあえずこれも独自リポジトリにしちゃう

cookbook 'php', github: "kambayashia/cookbooks-php"

これでvagrant upすればとりあえずいけた。
すでにberkshelfのがダウンロードされてたらberks updateも必要かも。

リポジトリはこちら
https://github.com/kambayashia/vagrant-files