Windows7ã«Chef(11.6.0)ã¨Vagrant(1.7.2)ãå ¥ãã¦ãããã¸ã§ãã³ã°ãã¦ã¿ã
ååMacã«Chefã¨Vagrantãå
¥ãã¦ãããã¸ã§ãã³ã°ãã¦ã¿ãã
Mac(Yosemite)にChef(12.0.3)とVagrant(1.7.2)を入れてプロビジョニングしてみた - カタカタブログ
ãã£ããVagrantfileã¨Chefã¯ãã¯ããã¯ãgitã§ç®¡çãã¦ããã°ã©ã®ç°å¢ã§ãä»®æ³ãã·ã³ãããã«ä¸ããããã¨ãããã¨ã§ãWindowsç°å¢ã§ããã®æ©æµã«é ããã¹ãããããã¸ã§ãã³ã°ç°å¢ãã»ããã¢ãããã¦ã¿ãï¼ãã ãä»åã¯æé å確èªã®ãããgit cloneã¯ããä¸ããæ§ç¯ãã¦ãã)ãçµè«ã¨ãã¦ãWindowsçã§ã®Chefç°å¢ã»ããã¢ããã¯Macããããé¢åã ã£ããã
æ§æ
åºæ¬çãªæ§æã¯ååMacã§ä½ã£ããã®ã¨åãããknife-soloã§Windowså´ããä»®æ³ãã¼ããã»ããã¢ãããããã¾ãããã¼ã«é¡ã®ãã¼ã¸ã§ã³ãç¾æç¹ã®ææ°çã§æããã
- ãã¹ãç°å¢: Windows 7 64bit
- ä»®æ³ãã¼ãOS: Cent OS 7
- Vagrant 1.7.2
- vagrant-vbguest (0.10.0): Virtual Box Guest Additionæ´æ°ã®ããã®ãã©ã°ã¤ã³
- vagrant-omnibus (1.4.1): ãã¹ãå´ããä»®æ³ãã¼ãã«Chefãã¤ã³ã¹ãã¼ã«ããããã®ãã©ã°ã¤ã³
- Virtual Box 4.3.20
- Ruby 2.1.5
- Chef 11.6.0
- knife-solo 0.4.2
- berkshelf 3.2.3Â
Virtual Boxã¨Vagrantã®ã¤ã³ã¹ãã¼ã«
ããããå
¬å¼ãµã¤ãããææ°çããã¦ã³ãã¼ãããã¤ã³ã¹ãã¼ã«ããããã§ã«ã¤ã³ã¹ãã¼ã«æ¸ã¿ã§ãæ®éã«ã¤ã³ã¹ãã¼ã©ãå®è¡ããã°ã¢ãããã¼ãããããããªã®ã§ãææ°åãã¦ããã
Vagrantãã©ã°ã¤ã³ã¤ã³ã¹ãã¼ã«
vagrant-vbguestã¤ã³ã¹ãã¼ã«
>Â vagrant plugin install vagrant-vbguest Installing the 'vagrant-vbguest' plugin. This can take a few minutes... Installed the plugin 'vagrant-vbguest (0.10.0)'!
vagrant-omnibusã¤ã³ã¹ãã¼ã«
>vagrant plugin install vagrant-omnibus Installing the 'vagrant-omnibus' plugin. This can take a few minutes... Â Â Â Installed the plugin 'vagrant-omnibus (1.4.1)'!
Cent OS 7ã®Boxãvagrantbox.esããcentos7ã¨ããååã§åå¾
> vagrant box add centos7 https://f0fff3908f081cb6461b407be80daf97f07ac418.googledrive.com/host/0BwtuV7VyVTSkUG1PM3pCeDJ4dVE/centos7.box
Vagrantã§centos7ä»®æ³ãã·ã³ä½æ
ä»®æ³ãã·ã³åæå
>vagrant init centos7 A `Vagrantfile` has been placed in this directory. You are now ready to `vagrant up` your first virtual environment! Please read the comments in the Vagrantfile as well as documentation on `vagrantup.com` for more information on using Vagrant.
Vagrantfileä½æ
ä½ã£ãVagrantfileã以ä¸ã®ããã«ç·¨éããã
# -*- mode: ruby -*- # vi: set ft=ruby : Vagrant.configure(2) do |config|  config.vm.box = "centos7"  config.vm.network "private_network", ip: "192.168.33.11"  config.vm.hostname = "vmcentos"  config.vbguest.auto_update = false # Guest Additionsèªåæ´æ°ç¡å¹  config.vm.provider "virtualbox" do |vb|vb.name = "centos7_vagrant"    vb.memory = "2048" end
ä»®æ³ãã·ã³èµ·å
>vagrant up (ã»ã»ã»ç¥) Failed to mount folders in Linux guest. This is usually because the "vboxsf" file system is not available. Please verify that the guest additions are properly installed in the guest and can work properly. The command attempted was: mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` vagrant /vagrant mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` vagrant /vagrant The error output from the last command was: /sbin/mount.vboxsf: mounting failed with the error: No such device
Macã®ã¨ãã¨åæ§ãååã¯Guest Additionsã¨Virtual Boxã®ãã¼ã¸ã§ã³ä¸ä¸è´ã¨ã©ã¼ãåºãã®ã§ãvagrant-vaguestã使ã£ã¦Guest Additionsãæ´æ°ããã
Guest Additionsæ´æ°
>vagrant vbguest
ä»®æ³ãã·ã³ã«sshãã°ã¤ã³
Macçã«ã¤ã³ã¹ãã¼ã«ããVagrantãªãã°ããã§vagrant sshã¨ããã°ãã°ã¤ã³ã§ããã®ã ããWindowsã«ã¯sshã³ãã³ãããªãããããã®æç¹ã§ã¯vagrant sshã³ãã³ãã§ãã°ã¤ã³ã§ããªãã対å¿ã®ããã«ã¯ãWindowsã§sshã³ãã³ããå®è¡ã§ããããã«ããå¿ è¦ãããããããã§ã¯åç´ãªåä½ç¢ºèªã®ããããã£ããTeraTermã§ãã°ã¤ã³ãããã¨ã«ããã
以ä¸ã®æ¥ç¶æ å ±ã§ãã°ã¤ã³ã§ãããã¨ã確èªããã
- ãã¹ã:ãã¼ã => 127.0.0.1:2222
- ã¦ã¼ã¶/ãã¹ã¯ã¼ã => vagrant/vagrant
ã¾ããhostsã«ä»¥ä¸ã®è¨å®ã追è¨ãã¦ããã
192.168.33.10Â Â Â Â vmcentos
ããã§sshã§vmcentos:22ã«vagrant/vagrantã§ãã°ã¤ã³ã§ãããã¨ãåããã¦ç¢ºèªãã¦ããã
Windowsãã¹ãå´ã«Chefã»ããã¢ãã
Rubyã»ããã¢ãã
Windowsã«Rubyã¨bundlerãã¤ã³ã¹ãã¼ã«ããå¿ è¦ãããããããã§ã¯æ§ç¯æé ãçç¥ããã注æç¹ã¨ãã¦ãWindowsã§Gemã使ã£ã¦Chefãã¤ã³ã¹ãã¼ã«ããããã«ãDevKitã¨ãããã®ããªãã¨ã¨ã©ã¼ã«ãªã£ã¦ãã¾ãã®ã§ã以ä¸ãåèã«DevKitãã¤ã³ã¹ãã¼ã«ããã
åè:Â http://www.rubylife.jp/railsinstall/rails/index4.html
1. 以ä¸ãã DevKit-mingw64-32-4.7.2-20130224-1151-sfx.exe ããã¦ã³ãã¼ã
http://rubyinstaller.org/downloads
2. ã¤ã³ã¹ãã¼ã©ãå®è¡ã以ä¸ã®ãã£ã¬ã¯ããªã«å±é(ãã©ã«ãã¯æ°è¦ã«ä½æãã)
C:\Ruby21\DevKit
3. ä¸è¨ãã£ã¬ã¯ããªã§ä»¥ä¸ã®ã³ãã³ããå®è¡
C:\Ruby21\DevKit>ruby dk.rb init [INFO] found RubyInstaller v2.1.5 at C:/Ruby21 Initialization complete! Please review and modify the auto-generated 'config.yml' file to ensure it contains the root directories to all of the installed Rubies you want enhanced by the DevKit.
4. ã¤ã³ã¹ãã¼ã«ã³ãã³ããå®è¡
C:\Ruby21\DevKit>ruby dk.rb install [INFO] Updating convenience notice gem override for 'C:/Ruby21' [INFO] Installing 'C:/Ruby21/lib/ruby/site_ruby/devkit.rb'
Gemfileã以ä¸ã®å 容ã§é ç½®
source 'https://rubygems.org' gem "win32-process" gem "windows-pr" gem âchef" gem "knife-solo" gem "win32-api", "~> 1.5.1", platforms: [:mingw, :x64_mingw] gem "berkshelf"
bundler install
C:\Ruby21\Gemfile>bundler install
ã»ç¢ºèª
>knife -v Chef: 11.6.0
knifeã³ãã³ããæ£ããå®è¡ã§ãããã¨ã確èª
Windowsãã¹ãå´ã«sshã¨rsyncãå ¥ãã¦ãã
sshã¨rsyncã¯Vagrantããã³Chefããä»®æ³ãã·ã³ã¸ã®ãããã¸ã§ãã³ã°æã«ãã°ã¤ã³ã¨ã¯ãã¯ããã¯ãã¡ã¤ã«è»¢éã«å¿ è¦ã ããWindowsã³ãã³ãããã³ããã§ã¯ããã©ã«ãã§ä½¿ããªããããMinGWãMSYSã使ã£ã¦ã¤ã³ã¹ãã¼ã«ããã
http://sourceforge.net/projects/mingw/files/
å
¬å¼ãµã¤ãããå
¥æããã¤ã³ã¹ãã¼ã«ãé²ããã¨ããã±ã¼ã¸ãé¸æã§ããã®ã§ãMSYS以ä¸ã®msys-openssh, msys-openssl, msys-rsync ãé¸æããInstallation > Apply Changes > Apply ã§ã¤ã³ã¹ãã¼ã«éå§
ã¤ã³ã¹ãã¼ã«å¾ãC:\MinGW\msys\1.0\bin ãPATHã«è¿½å
ããã«ãããvagrant sshãWindowsã§ã使ããããã«ãªã£ãã
>vagrant ssh Last login: Thu Feb 12 21:20:21 2015 from 192.168.33.1 [vagrant@vmcentos ~]$
ssh-configè¨å®
ãã®ã¾ã¾ã ã¨sshæã«ãã¹ã¯ã¼ãå ¥åãæ±ããããã®ã§ãssh vmcentos7ã§ãã¹ã¯ã¼ãç¡ãvagrantã¦ã¼ã¶ã§ãã°ã¤ã³ã§ããããã«ãã¦ããã
>vagrant ssh-config --host vmcentos >> C:\MinGW\msys\1.0\etc\ssh \ssh_config
ä»®æ³ãã·ã³ã«Chefã¤ã³ã¹ãã¼ã«
>knife solo bootstrap vagrant@vmcentos
ä»®æ³ãã·ã³ã«ãã°ã¤ã³ããChefãã¤ã³ã¹ãã¼ã«ããããã¨ã確èª
C:\vms\centos7>ssh vmcentos Last login: Fri Feb 13 00:37:52 2015 from 192.168.33.1 [vagrant@vmcentos ~]$ knife -v Chef: 11.6.0
Chefã¯ãã¯ããã¯ä½æ
ã¯ãã¯ããã¯ã®ã²ãªå½¢ä½æ
>knife solo init . WARNING: No knife configuration file found Creating kitchen... Creating knife.rb in kitchen... Creating cupboards... DL is deprecated, please use Fiddle Setting up Berkshelf...
apacheã®ã¯ãã¯ããã¯ä½æ
>knife cookbook create apache -o site-cookbooks ** Creating cookbook apache ** Creating README for cookbook: apache ** Creating CHANGELOG for cookbook: apache ** Creating metadata for cookbook: apache
apacheã®ã¬ã·ãä½æ
site-cookbooks\apache\recipes\default.rb ã以ä¸ã®å 容ã§ç·¨éããã
package "httpd" do  action :install end service "httpd" do  action [ :enable, :start ] end
ã»ãã¼ãæ
å ±è¨è¼
nodes\vmcentos.jsonã«apacheã¬ã·ãã追å
{ Â "run_list": [ "recipe[apache]" Â ], Â "automatic": { Â Â "ipaddress": "vmcentos" Â } }
Chef-soloãå®è¡ãapacheãã¤ã³ã¹ãã¼ã«
ã¬ã·ãå®è¡
>knife solo cook vmcentos DL is deprecated, please use Fiddle Running Chef on vmcentos... Checking Chef version... Installing Berkshelf cookbooks to 'cookbooks'... DEPRECATED: Your Berksfile contains a site location pointing to the Opscode Comm unity Site (site :opscode). Site locations have been replaced by the source loca tion. Change this to: 'source "https://supermarket.chef.io"' to remove this warn ing. For more information visit https://github.com/berkshelf/berkshelf/wiki/depr ecated-locations Resolving cookbook dependencies... Uploading the kitchen... rsync: change_dir "/cygdrive/C/Ruby21/lib/ruby/gems/2.1.0/gems/knife-solo-0.4.2/ lib/knife-solo/resources/patch_cookbooks" failed: Bad file number (9) rsync error: some files/attrs were not transferred (see previous errors) (code 2 3) at /usr/src/rsync/rsync-3.0.8/main.c(1052) [sender=3.0.8] ERROR: RuntimeError: Failed to launch command ["rsync", "-rL", "--chmod=ugo=rwX" , "--rsh=ssh vagrant@vmcentos", "--delete-after", "--exclude=revision-deploys", "--exclude=tmp", "--exclude=.git", "--exclude=.hg", "--exclude=.svn", "--exclude =.bzr", "/cygdrive/C/Ruby21/lib/ruby/gems/2.1.0/gems/knife-solo-0.4.2/lib/knife- solo/resources/patch_cookbooks/", ":~/chef-solo/cookbooks-1"]
rsyncã§ã¨ã©ã¼ã¨ãªã£ã¦ããããã/cygdrive/Cã¨ãããã¹ã§ã¯ãã¯ããã¯ãè¦ã¦ããããã対çã¨ãã¦ã/cygdriveããã¦ã³ããã¦ãã¾ãããã¨ã«ããã
/cygdriveãã¦ã³ã
C:\MinGW\msys\1.0\etc\fstabãç·¨éãã以ä¸ã®å 容ãè¨è¼ãã
#Win32_Path            Mount_Point c:             /cygdrive/c
ããã§/cygdrive/cã¨ãããã¹ã«ã¢ã¯ã»ã¹ããã¨C:ãã©ã¤ãç´ä¸ã«ã¢ã¯ã»ã¹ãããã¨ã«ãªãã®ã§ã/cygdrive/C/Ruby21ã»ã»ã»ã¨ãããã¹ã§ã¡ããã¨C:ãã©ã¤ã以ä¸ã®æ£ãããã¹ã«ã¢ã¯ã»ã¹ã§ããã¯ãã
ã¬ã·ãåå®è¡
>knife solo cook vmcentos DL is deprecated, please use Fiddle Running Chef on vmcentos... Checking Chef version... Installing Berkshelf cookbooks to 'cookbooks'... DEPRECATED: Your Berksfile contains a site location pointing to the Opscode Comm unity Site (site :opscode). Site locations have been replaced by the source loca tion. Change this to: 'source "https://supermarket.chef.io"' to remove this warn ing. For more information visit https://github.com/berkshelf/berkshelf/wiki/depr ecated-locations Resolving cookbook dependencies... Uploading the kitchen... WARNING: Local cookbook_path 'C:/vms/centos7/cookbooks' does not exist Generating solo config... Running Chef... Starting Chef Client, version 11.6.0 Compiling Cookbooks... Converging 2 resources Recipe: apache::default  * package[httpd] action install   - install version 2.4.6-19.el7.centos of package httpd  * service[httpd] action enable   - enable service service[httpd]  * service[httpd] action start   - start service service[httpd] Chef Client finished, 3 resources updated
ä»åº¦ã¯æåããï¼
ä»®æ³ãã·ã³ã«ãã°ã¤ã³ãapacheåä½ç¢ºèª
ä»®æ³ãã·ã³ã«ãã°ã¤ã³ãã
[vagrant@vmcentos /]$ ps -ef | grep httpd | grep -v grep root     5081    1 0 03:16 ?       00:00:00 /usr/sbin/httpd -DFOREGROUND apache   5082 5081 0 03:16 ?       00:00:00 /usr/sbin/httpd -DFOREGROUND apache   5083 5081 0 03:16 ?       00:00:00 /usr/sbin/httpd -DFOREGROUND apache   5084 5081 0 03:16 ?       00:00:00 /usr/sbin/httpd -DFOREGROUND apache   5085 5081 0 03:16 ?       00:00:00 /usr/sbin/httpd -DFOREGROUND apache   5086 5081 0 03:16 ?       00:00:00 /usr/sbin/httpd -DFOREGROUND
apacheãã¤ã³ã¹ãã¼ã«ãããèµ·åãã¦ããï¼
ã¾ã¨ã
ååã®Mac OSã«å¼ãç¶ã ãä»åã¯Windows7ä¸ã§åä¸ã®VagrantãChefãã»ããã¢ãããã¦ã¿ãããã¯ãWindowsã ã¨å種ãã¼ã«ãç¹ã«ã³ãã³ãã©ã¤ã³å¨ããLinuxç³»OSã¨éã£ã¦è²§å¼±ãªããã追å ã§ã»ããã¢ããããªãã¨ãããªãå 容ãå¢ãã¦ãã¾ãããã ãã»ããã¢ãããå®äºãã¦ãã¾ãã°ããã¨ã¯Vagrantfileã¨ã¯ãã¯ããã¯ã ãã§Macã¨å¤ãããã«ä»®æ³ãã¼ãã®ãããã¸ã§ãã³ã°ãã§ããã®ã§ãããã§Windowsã¨Macã§åä¸ã®OSæ§æãgitçã§ç®¡çãããã¨ãã§ããããã«ãªã£ãï¼
以ä¸