のぶLab.

流しのソフトウェアエンジニアの雑記帳. Android, Scala, Clojure, Ruby on Railsなど

Vagrant+ChefでDjangoをインストール

VagrantとChefを使ってDjangoをインストールします。

opscodeで公開されているPythonのcookbookを使ってインストールが可能です。
https://github.com/poise/python
こちらのcookbookではPythonと一緒にpipやvirtualenvもインストールしてくれます。
Djangoのインストールは自作のcookbookからpython::pip経由でインストールを行います。

1.site-cookbooksにDjangoをインストールするcookbookを作成

ここではcustomというcookbookを作成します。

cd site-cookbooks
berks cookbook custom

2. default.rbの編集

作成したcustom cookbookのrecipes/default.rbを編集します。

include_recipe "python::pip"

python_pip django do
	version "1.6.1"
	action :install
end

3.Berksfile, Vagrantfileでpython,custom cookbookを指定する

python cookbookはサードパーティ性のcookbookをインストールする手順と同様です。
custom cookbookはBerksfileで path: 'site-cookbooks/customs' としていしてあげてください。

Berksfile

cookbook 'python'
cookbook 'customs', '~> 0.1.0', path: 'site-cookbooks/customs'

Vagrantfile

   ...
config.vm.provision :chef_solo do |chef|
   chef.add_recipe "python"
   chef.add_recipe "custom"

   chef.json = {
      "python" => {
        "instal_method" => "source",
        "version" => "2.7.3",
      },
      ...
   }
end
   ...