** 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で苦労したよ]]

*** vagrant-omnibus を導入 [#r17cc53c]
- [[Vagrant公式サイト>http://www.vagrantbox.es/]] からダウンロードしたbox内にchef-soloがインストールされていない場合、boxにchef-soloをインストールする手間が面倒なので、ここでは [[vagrant-omnibus>http://www.ryuzee.com/contents/blog/6651]] プラグインをいれます([[veewee>http://qiita.com/luckypool/items/7fadabc83ed763cadc0b]]で、自作boxとして作ったときも便利)。
 C:\> vagrant plugin install vagrant-omnibus
 C:\> vagrant plugin list
 vagrant-login (1.0.1, system)
 vagrant-omnibus (1.4.1)
 vagrant-share (1.0.1, system)

*** VMの起動やら、やらやら [#zff3a5b8]
- [[Vagrant + chef-solo を導入してみる]] で、"Hello, Chef!"作った環境に、''Vagrantfile'' を作ってゲストOSをセットアップしてみます。(C:\Users\hoge\chef-repo\Vagrantfile)
 Vagrant.configure("2") do |config|
   config.vm.box = "CentOS6.5"
   config.vm.box_url = "https://github.com/2creatives/vagrant-centos/releases/download/v6.5.3/centos65-x86_64-20140116.box"
   config.omnibus.chef_version = :latest
 
   config.vm.define :chef1 do |chef1|
     chef1.vm.network :forwarded_port, guest: 22, host: 2222, host_ip: "127.0.0.1", id: "ssh", auto_correct: true
 
     chef1.vm.provider "virtualbox" do |v| 
       v.customize ["modifyvm", :id, "--memory", 512] 
     end
 
     chef1.vm.provision :chef_solo do |chef|
       chef.custom_config_path = "Vagrantfile.chef"
       chef.cookbooks_path = "./cookbooks"
       chef.add_recipe "hello"
     end
 
   end
 end
- VM を起動する(と、boxにshef-soloがインストールされるのでズラズラ…表示されます)
 C:\Users\hoge\chef-repo> vagrant reload   ※または vagrant up chef1
-- どきどき
 …
 Generating chef JSON and uploading...
 Running chef-solo...
 [2014-05-18T14:04:18+00:00] INFO: Forking chef instance to converge...
 [2014-05-18T14:04:18+00:00] INFO: *** Chef 11.12.4 ***
 [2014-05-18T14:04:18+00:00] INFO: Chef-client pid: 1981
 [2014-05-18T14:04:25+00:00] INFO: Setting the run_list to ["recipe[hello]"] from CLI options
 [2014-05-18T14:04:25+00:00] INFO: Run List is [recipe[hello]]
 [2014-05-18T14:04:25+00:00] INFO: Run List expands to [hello]
 [2014-05-18T14:04:25+00:00] INFO: Starting Chef Run for vagrant-centos65.vagrantup.com
 [2014-05-18T14:04:25+00:00] INFO: Running start handlers
 [2014-05-18T14:04:25+00:00] INFO: Start handlers complete.
 [2014-05-18T14:04:25+00:00] INFO: Hello, Chef!                ←← きたー
 [2014-05-18T14:04:25+00:00] INFO: Chef Run complete in 0.027871938 seconds
 [2014-05-18T14:04:25+00:00] INFO: Running report handlers
 [2014-05-18T14:04:25+00:00] INFO: Report handlers complete
- このまま使ってもいいけど、セキュリティ的にあれなので「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)

*** 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: Chef 11.12.4 Omnibus package is already installed.
 ==> chef1: Running provisioner: chef_solo...
 Generating chef JSON and uploading...
 Running chef-solo...
 [2014-05-18T14:16:58+00:00] INFO: Forking chef instance to converge...
 [2014-05-18T14:16:58+00:00] INFO: *** Chef 11.12.4 ***
 [2014-05-18T14:16:58+00:00] INFO: Chef-client pid: 2425
 [2014-05-18T14:17:05+00:00] INFO: Setting the run_list to ["recipe[hello]"] from CLI options
 [2014-05-18T14:17:05+00:00] INFO: Run List is [recipe[hello]]
 [2014-05-18T14:17:05+00:00] INFO: Run List expands to [hello]
 [2014-05-18T14:17:05+00:00] INFO: Starting Chef Run for vagrant-centos65.vagrantup.com
 [2014-05-18T14:17:05+00:00] INFO: Running start handlers
 [2014-05-18T14:17:05+00:00] INFO: Start handlers complete.
 [2014-05-18T14:17:05+00:00] INFO: Hello, Chef!
 [2014-05-18T14:17:40+00:00] INFO: package[zsh] installing zsh-4.3.10-7.el6 from base repository  ←← きたー
 [2014-05-18T14:17:52+00:00] INFO: Chef Run complete in 47.358591173 seconds
 [2014-05-18T14:17:52+00:00] INFO: Running report handlers
 [2014-05-18T14:17:52+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]]
- [[Vagrantでknife-solo+Serverspecなboxを作っていた話>http://a3no.hatenablog.com/entry/2013/09/08/230712]]

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