** vagrant provision経由でゲストOSにパッケージ導入 [#x5853044]
- ホストOS:Windows7、ゲストOS:CentOS 6.4の条件で試してみてます。
- windowsコマンドから、chef-solo 叩くもエラーとなってしまったわけです。windows上で knife の環境を作ってみたんですが、どうやっても上手くいかなかったので Vagrantfile に chef-solo の記述を書く方法としました。
-- windows側で「Hello」まで出した環境を作成していることが前提 / [[chef-soloを動かすのにrubyで苦労したよ>chef-soloを動かすのにrubyで苦労したよ]]

*** とりあえず centos のbox いれてみる。そして…。 [#sfbc47e8]
- こんな感じで Vagrantfile を作ってゲストOSをセットアップしてみます。(C:\Users\hoge\Vagrantfile)
 Vagrant.configure("2") do |config|
   config.vm.box = "CentOS-6.3-x86_64-v20130101"
   config.vm.box_url = "http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.3-x86_64-v20130101.box"
 
   config.vm.define :chef1 do |chef1|
     chef1.vm.network :forwarded_port, guest: 22, host: 2230, host_ip: "127.0.0.1", id: "ssh", auto_correct: true
     chef1.vm.network :private_network, ip: "192.168.10.12"
   end
 
 end
- このまま使ってもいいけど、セキュリティ的にあれなので「yum updage」をしてみると…。ゲストOSを立ち上げたとき下記のエラーが出力され共有ディレクトリが使用できないと怒られる。
 [chef1] -- /vagrant
 The following SSH command responded with a non-zero exit status.
 Vagrant assumes that this means the command failed!
-- vboxをリビルドしてやる / [[Vagrantでmountエラーで、フォルダがShareされない>http://blog.mizoshiri.com/archives/1390]]
 [root@localhost vagrant]# /etc/init.d/vboxadd setup
 Removing existing VirtualBox non-DKMS kernel modules       [  OK  ]
 Building the VirtualBox Guest Additions kernel modules
 Building the main Guest Additions module                   [  OK  ]
 Building the shared folder support module                  [  OK  ]
 Building the OpenGL support module                         [FAILED]
 (Look at /var/log/vboxadd-install.log to find out what went wrong)
 Doing non-kernel setup of the Guest Additions              [  OK  ]
- ゲストOS再起動して、/vagrant がマウントされていることを確認する。(先に進めないからね)
-- 蛇足、centos のバージョン確認方法
 [root@localhost vagrant]#  cat /etc/redhat-release
 CentOS release 6.4 (Final)

*** provision の設定 [#l7b1309f]
- provision の設定を Vagrantfile にいれてみる。(C:\Users\hoge\Vagrantfile)
 Vagrant.configure("2") do |config|
   config.vm.box = "CentOS-6.3-x86_64-v20130101"
   config.vm.box_url = "http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.3-x86_64-v20130101.box"
 
   config.vm.define :chef1 do |chef1|
     chef1.vm.network :forwarded_port, guest: 22, host: 2230, host_ip: "127.0.0.1", id: "ssh", auto_correct: true
     chef1.vm.network :private_network, ip: "192.168.10.12"
   end
 
   config.vm.provision :chef_solo do |chef|
     chef.cookbooks_path = "./chef-repo/cookbooks"
     chef.add_recipe "hello"
   end
 
 end
- この状態でゲストOSを再起動してみる。
 C:\Users\hoge\chef-repo> vagrant reload
-- どきどき
 …
 [chef1] Mounting shared folders...
 [chef1] -- /vagrant
 [chef1] -- /tmp/vagrant-chef-1/chef-solo-1/cookbooks
 [chef1] Running provisioner: chef_solo...
 Generating chef JSON and uploading...
 Running chef-solo...
 [2013-08-20T09:42:34+00:00] INFO: *** Chef 10.16.4 ***
 [2013-08-20T09:42:34+00:00] INFO: Setting the run_list to ["recipe[hello]"] from JSON
 [2013-08-20T09:42:34+00:00] INFO: Run List is [recipe[hello]]
 [2013-08-20T09:42:34+00:00] INFO: Run List expands to [hello]
 [2013-08-20T09:42:34+00:00] INFO: Starting Chef Run for localhost
 [2013-08-20T09:42:34+00:00] INFO: Running start handlers
 [2013-08-20T09:42:34+00:00] INFO: Start handlers complete.
 [2013-08-20T09:42:34+00:00] INFO: Hello, Chef!                ←← きたー
 [2013-08-20T09:42:34+00:00] INFO: Chef Run complete in 0.025701 seconds
 [2013-08-20T09:42:34+00:00] INFO: Running report handlers
 [2013-08-20T09:42:34+00:00] INFO: Report handlers complete

*** zsh をいれてみる [#q7813266]
- default.rb を編集
 C:\Users\hoge\chef-repo\cookbooks\hello\recipes> notepad default.rb

 #
 # Cookbook Name:: hello
 # Recipe:: default
 #
 # Copyright 2013, YOUR_COMPANY_NAME
 #
 # All rights reserved - Do Not Redistribute
 #
 log "Hello, Chef!"
 
 package "zsh" do
    action :install
 end
- provision 実行!
 C:\Users\hoge\chef-repo> vagrant provision
 
 [chef1] Running provisioner: chef_solo...
 Generating chef JSON and uploading...
 Running chef-solo...
 [2013-08-20T09:50:57+00:00] INFO: *** Chef 10.16.4 ***
 [2013-08-20T09:50:57+00:00] INFO: Setting the run_list to ["recipe[hello]"] from JSON
 [2013-08-20T09:50:57+00:00] INFO: Run List is [recipe[hello]]
 [2013-08-20T09:50:57+00:00] INFO: Run List expands to [hello]
 [2013-08-20T09:50:57+00:00] INFO: Starting Chef Run for localhost
 [2013-08-20T09:50:57+00:00] INFO: Running start handlers
 [2013-08-20T09:50:57+00:00] INFO: Start handlers complete.
 [2013-08-20T09:50:57+00:00] INFO: Hello, Chef!
 [2013-08-20T09:51:00+00:00] INFO: package[zsh] installing zsh-4.3.10-5.el6 from base repository  ←← きたー
 [2013-08-20T09:51:09+00:00] INFO: Chef Run complete in 11.632397 seconds
 [2013-08-20T09:51:09+00:00] INFO: Running report handlers
 [2013-08-20T09:51:09+00:00] INFO: Report handlers complete

*** 参考にさせて頂いたサイト様 [#r86711d4]
- [[VagrantとChef-soloについて学んだいくつかのこと>http://iakio.hatenablog.com/entry/20120512/1336825545]]
- [[VagrantとChef-soloについて初歩の備忘>http://havelog.ayumusato.com/develop/server/e562-vagrant_with_chef.html]]

トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS