Chef Solo + vagrant で環境構築について学ぶ
Chefで最近環境構築することが社内でも多くなってきたので、自分も学習のためにvagrantを使ってVM環境で試す事にした。
最初に参考にしたのはここです。
$ mkdir chef-study
$ cd chef-study
$ vagrant init
続いて生成されたVagrantファイルを編集
4 Vagrant.configure("2") do |config| 5 # All Vagrant configuration is done here. The most common configuration 6 # options are documented and commented below. For a complete reference, 7 # please see the online documentation at vagrantup.com. 8 9 # Every Vagrant virtual environment requires a box to build off of. 10 config.vm.box = "centos" ・・・・ ・・・・・ 128 config.omnibus.chef_version = :latest 129 config.berkshelf.enabled = true
今回はOSはcentosにします。下の2行はberkshelf(Vegrantのプラグインを管理する)の設定です。
$ vagrant plugin install vagrant-omnibus
$ vagrant plugin install vagrant-berkshelf
Berffileにプラグインのダウンロード先を追加します。
site :opscode
続いてsite-cookbooksというフォルダを作成し、site-cookbook直下でberkコマンドを打ってレシピの雛形を生成します。
$ cd site-cookbook
$ berks cookbook hello
続いてBerffileをまた編集します。
1 site :opscode
2 cookbook "hello" , path: "site-cookbooks/hello"
そしてsite-cookbooks/hello/recipe/default.rbを編集します。
1 #
2 # Cookbook Name:: hello
3 # Recipe:: default
4 #
5 # Copyright (C) 2013 YOUR_NAME
6 #
7 # All rights reserved - Do Not Redistribute
8 #
9
10 log "Hello !!!!!!!!!!"
最後にVagrantfileに追記
99 config.vm.provision :chef_solo do |chef| 100 # chef.chef_server_url = "https://api.opscode.com/organizations/ORGNAME" 101 # chef.validation_key_path = "ORGNAME-validator.pem" 102 chef.run_list = ["hello"] 103 114 end
確認はvagrantコマンドで
$ vagrant destroy
$ vagrant up
まずはこれでVM上に環境が出来た。
では、次はjava/ruby ,tomcat/unicorn,nginxなど言語やミドルウェアを入れてみよう。