Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

Chef | cookbook | Ubuntu1204環境のdesktopのインストールをするcookbook

概要

Ubuntu1204環境のdesktopのインストールをするcookbook

詳細

Ubuntu1204環境のdesktopのインストールをするcookbookを作成します。

手順

# kitchenの作成
mkdir ubuntu_desktop_cookbook
cd ubuntu_desktop_cookbook
knife solo init .

# Vagrantfile生成
vagrant init

# Vagrantfile編集 ※詳細は後述
vi Vagrantfile

# cookbookのテンプレート生成
knife cookbook create ubuntu_desktop -o site-cookbooks/

# recipeの編集 ※詳細は後述

# vagrant起動
vagrant up
vagrant provision
vagrant halt

# 再起動後にデスクトップのインストール確認ができる
vagrant up
Vagrantfile

apt_get_updateについては詳細を記述しませんが、sudo apt-get updateしているだけです。

# -*- 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 = "ubuntu-12.04-x64"
  config.omnibus.chef_version = "11.6.0"
  config.vm.network :private_network, ip: "192.168.33.24"

  config.vm.provider :virtualbox do |vb|
    vb.name = "ubuntu_desktop"
    vb.gui = true
    vb.customize ["modifyvm", :id, "--memory", 1024]
    vb.customize ["modifyvm", :id, "--vram", 10] # 9MB以上を指定する必要がある
  end

  config.vm.provision :chef_solo do |chef|
    chef.cookbooks_path = ["./cookbooks", "./site-cookbooks"]
    chef.add_recipe "apt_get_update"
    chef.add_recipe "ubuntu_desktop"
  end
end
site-cookbooks/ubuntu_desktop/libraries/helper.rb
class Chef
  class Recipe
    def execute_with_log(name, &block)
      log "start #{name}"
      block.call
      log "end   #{name}"
    end
  end
end
site-cookbooks/ubuntu_desktop/recipes/default.rb
execute_with_log("install ubuntu desktop") do
  package "ubuntu-desktop" do
    action :install
  end
end