Tbpgr Blog

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

Chef | Role

概要

Role

詳細

RoleにはNode間にまたがる設定を保存する。
0〜n個のAttributesとrun listを設定可能です。
RoleはNodeで指定可能です。

フォーマット

RubyDSLJSONの2パターンの記述方法を利用可能

サンプル

前提

vagrantを利用

仕様

・apt-get update,gitのクックブックをrun listに持つRoleを作成
・Roleとは別にtreeをクックブックを指定

roles/apt_update_git.rb
name "apt_update_git"
description "apt-get update, git install"
run_list "recipe[apt_get_update]", "recipe[git]"
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 = "ubuntu-12.04-x64"
  config.omnibus.chef_version = "11.6.0"
  config.vm.network :private_network, ip: "192.168.33.23"

  config.vm.provider :virtualbox do |vb|
    vb.name = "role_sample"
    vb.customize ["modifyvm", :id, "--memory", 512]
  end

  config.vm.provision :chef_solo do |chef|
    chef.cookbooks_path = ["./cookbooks", "./site-cookbooks"]
    chef.data_bags_path = "data_bags"
    chef.roles_path = "roles"
    chef.add_role "apt_update_git"
    chef.add_recipe "tree"
  end
end

recipe

各種レシピの内容は省略

プロビジョニング実行後確認

$ git --version
git version 1.7.9.5
$ tree --version
tree v1.5.3 (c) 1996 - 2009 by Steve Baker, Thomas Moore, Francesc Rocher, Kyosuke Tokoro