knife-soloç¨boxãchefã§ä½ã£ã¦ã¿ã
以åã「Vagrantでknife-solo+Serverspecなboxを作っていた話」ã§ãã使¥ã
Chef使ã£ã¦ãã®ã«æä½æ¥ã¯ãªãããã¨Chefã®ã¬ã·ãã«è½ã¨ãè¾¼ãã§ã¿ã¾ããã
ä½ã£ãã¬ã·ãã¯ä»¥ä¸ã
[site-cookbooks/knifesolobox/recipes/default.rb]
execute "install-chef" do user "root" command "curl -L https://www.opscode.com/chef/install.sh | bash" end %w{knife-solo rake serverspec}.each do |gem| gem_package "#{gem}" do gem_binary("/opt/chef/embedded/bin/gem") options("--no-ri --no-rdoc") end end %w{rake rspec}.each do |bin| link "/usr/sbin/#{bin}" do to "/opt/chef/embedded/bin/#{bin}" end end directory "/home/vagrant/.chef" do owner "vagrant" group "vagrant" mode "0775" end cookbook_file "/home/vagrant/.chef/knife.rb" do source "knife.rb" owner "vagrant" group "vagrant" mode "0644" end %w{insecure_private_key config}.each do |file| cookbook_file "/home/vagrant/.ssh/#{file}" do source "#{file}" owner "vagrant" group "vagrant" mode "0600" end end link "/home/vagrant/chef-repo" do to "/vagrant" end
[site-cookbooks/knifesolobox/files/default/knife.rb]
log_level :info log_location STDOUT node_name 'vagrant' client_key '/home/vagrant/.chef/vagrant.pem' validation_client_name 'chef-validator' validation_key '/etc/chef-server/chef-validator.pem' chef_server_url 'https://vagrant-ubuntu-precise-64:443' syntax_check_cache_path '/home/vagrant/.chef/syntax_check_cache' knife[:solo_path] = '/tmp/chef-solo'
ä½ãåªçæ§ã¨ãã¯ãã ãã£ã¦ãªããã¾ãã¯ã¬ã·ãåãéè¦ã
.ssh/configã¨.ssh/insecure_private_keyã¯ååè¨äºãåç
§ã®ãã¨ã
Vagrantfileã¯ä»¥ä¸ã
Vagrant.configure("2") do |config| config.vm.box = "precise64official" config.vm.provision "chef_solo" do |chef| chef.add_recipe "knifesolobox" chef.cookbooks_path = "/path/to/chef-repo/site-cookbooks" end end
å®è¡ãã¦ã¿ã¾ãã
C:\vagrant\work\createbox>vagrant up Bringing machine 'default' up with 'virtualbox' provider... [default] Importing base box 'precise64official'... [0K[default] Matching MAC address for NAT networking... [default] Setting the name of the VM... [default] Clearing any previously set forwarded ports... [default] Fixed port collision for 22 => 2222. Now on port 2200. [default] Creating shared folders metadata... [default] Clearing any previously set network interfaces... [default] Preparing network interfaces based on configuration... [default] Forwarding ports... [default] -- 22 => 2200 (adapter 1) [default] Booting VM... [default] Waiting for machine to boot. This may take a few minutes... [default] Machine booted and ready! [default] The guest additions on this VM do not match the installed version of VirtualBox! In most cases this is fine, but in rare cases it can cause things such as shared folders to not work properly. If you see shared folder errors, please update the guest additions within the virtual machine and reload your VM. Guest Additions Version: 4.1.12 VirtualBox Version: 4.2 [default] Mounting shared folders... [default] -- /vagrant [default] -- /tmp/vagrant-chef-1/chef-solo-1/cookbooks [default] Running provisioner: chef_solo... The chef binary (either `chef-solo` or `chef-client`) was not found on the VM and is required for chef provisioning. Please verify that chef is installed and that the binary is available on the PATH.
ãããµããã
Chefã§Provisioningããã®ã«Boxã«äºåã«chef-soloå¿
è¦ãªãã§ããã
æ®æ®µãknife-soloãããã¦ãªãã£ãã®ã§ç¥ããªãã£ãã
ããã§Ryuzeeããã紹介されているvagrant-omnibus pluginã使ããã¨ã«ãã¾ããã
Ryuzeeãããæ¸ããã¦ã¾ããã
knife-soloç¨ã®Boxãä½ãã®ã«chef-soloãæã§å
¥ããã¨ããªããéããã
ããããã·ã§ã«ã§Provisioningãã¦å
¥ãã¦ãããããã¨æã£ããã©
cookbookãéä¸ã§rsyncåºæ¥ããã ã£ãï¼ã¨ãæã£ã¦æå¿µãã¾ããã
pluginã¤ã³ã¹ãã¼ã«ã
C:\vagrant\work\createbox>vagrant plugin install vagrant-omnibus Installing the 'vagrant-omnibus' plugin. This can take a few minutes... Installed the plugin 'vagrant-omnibus (1.1.1)'!
ããã§Chefã¯ã¤ã³ã¹ãã¼ã«ãããã¯ããªã®ã§ã
åã®ã¬ã·ãã®æåã®executeã¯åã£ã¦ããã¾ãã
ãããããVagrantfileã«ä»¥ä¸ã追å ã
config.omnibus.chef_version = :latest
å®è¡ãã¦ã¿ã¾ãã
C:\vagrant\work\createbox>vagrant up Bringing machine 'default' up with 'virtualbox' provider... [default] Importing base box 'precise64official'... [0K[default] Matching MAC address for NAT networking... [default] Setting the name of the VM... [default] Clearing any previously set forwarded ports... [default] Creating shared folders metadata... [default] Clearing any previously set network interfaces... [default] Preparing network interfaces based on configuration... [default] Forwarding ports... [default] -- 22 => 2222 (adapter 1) [default] Booting VM... [default] Waiting for machine to boot. This may take a few minutes... [default] Machine booted and ready! [default] The guest additions on this VM do not match the installed version of VirtualBox! In most cases this is fine, but in rare cases it can cause things such as shared folders to not work properly. If you see shared folder errors, please update the guest additions within the virtual machine and reload your VM. Guest Additions Version: 4.1.12 VirtualBox Version: 4.2 [default] Mounting shared folders... [default] -- /vagrant [default] -- /tmp/vagrant-chef-1/chef-solo-1/cookbooks [default] Installing Chef 11.6.0 Omnibus package... [default] Running provisioner: chef_solo... Generating chef JSON and uploading... Running chef-solo... stdin: is not a tty [2013-09-15T22:09:31+00:00] INFO: Forking chef instance to converge... [2013-09-15T22:09:31+00:00] INFO: *** Chef 11.6.0 *** [2013-09-15T22:09:31+00:00] INFO: Setting the run_list to ["recipe[knifesolobox]"] from JSON [2013-09-15T22:09:31+00:00] INFO: Run List is [recipe[knifesolobox]] [2013-09-15T22:09:31+00:00] INFO: Run List expands to [knifesolobox] [2013-09-15T22:09:31+00:00] INFO: Starting Chef Run for vagrant-ubuntu-precise-64 [2013-09-15T22:09:31+00:00] INFO: Running start handlers [2013-09-15T22:09:31+00:00] INFO: Start handlers complete. [2013-09-15T22:10:14+00:00] INFO: link[/usr/sbin/rake] created [2013-09-15T22:10:14+00:00] INFO: link[/usr/sbin/rspec] created [2013-09-15T22:10:14+00:00] INFO: directory[/home/vagrant/.chef] created directory /home/vagrant/.chef [2013-09-15T22:10:14+00:00] INFO: directory[/home/vagrant/.chef] owner changed to 1001 [2013-09-15T22:10:14+00:00] INFO: directory[/home/vagrant/.chef] group changed to 1001 [2013-09-15T22:10:14+00:00] INFO: directory[/home/vagrant/.chef] mode changed to 775 [2013-09-15T22:10:14+00:00] INFO: cookbook_file[/home/vagrant/.chef/knife.rb] created file /home/vagrant/.chef/knife.rb [2013-09-15T22:10:14+00:00] INFO: cookbook_file[/home/vagrant/.chef/knife.rb] updated file contents /home/vagrant/.chef/knife.rb [2013-09-15T22:10:14+00:00] INFO: cookbook_file[/home/vagrant/.chef/knife.rb] owner changed to 1001 [2013-09-15T22:10:14+00:00] INFO: cookbook_file[/home/vagrant/.chef/knife.rb] group changed to 1001 [2013-09-15T22:10:14+00:00] INFO: cookbook_file[/home/vagrant/.chef/knife.rb] mode changed to 644 [2013-09-15T22:10:14+00:00] INFO: cookbook_file[/home/vagrant/.ssh/insecure_private_key] created file /home/vagrant/.ssh/insecure_private_key [2013-09-15T22:10:14+00:00] INFO: cookbook_file[/home/vagrant/.ssh/insecure_private_key] updated file contents /home/vagrant/.ssh/insecure_private_key [2013-09-15T22:10:14+00:00] INFO: cookbook_file[/home/vagrant/.ssh/insecure_private_key] owner changed to 1001 [2013-09-15T22:10:14+00:00] INFO: cookbook_file[/home/vagrant/.ssh/insecure_private_key] group changed to 1001 [2013-09-15T22:10:14+00:00] INFO: cookbook_file[/home/vagrant/.ssh/insecure_private_key] mode changed to 600 [2013-09-15T22:10:14+00:00] INFO: cookbook_file[/home/vagrant/.ssh/config] created file /home/vagrant/.ssh/config [2013-09-15T22:10:14+00:00] INFO: cookbook_file[/home/vagrant/.ssh/config] updated file contents /home/vagrant/.ssh/config [2013-09-15T22:10:14+00:00] INFO: cookbook_file[/home/vagrant/.ssh/config] owner changed to 1001 [2013-09-15T22:10:14+00:00] INFO: cookbook_file[/home/vagrant/.ssh/config] group changed to 1001 [2013-09-15T22:10:14+00:00] INFO: cookbook_file[/home/vagrant/.ssh/config] modechanged to 600 [2013-09-15T22:10:14+00:00] INFO: link[/home/vagrant/chef-repo] created [2013-09-15T22:10:14+00:00] INFO: Chef Run complete in 43.603384421 seconds [2013-09-15T22:10:14+00:00] INFO: Running report handlers [2013-09-15T22:10:14+00:00] INFO: Report handlers complete
ã§ãã¾ããã
ãã¨ã¯vagrant packageããã°ãbox宿ã§ãã
æè»½ã«ã¯åºæ¥ã¾ãããpluginã使ã£ãã®ã§ã¤ãã¤ããªæãããã¾ãã
ãã¯ãboxä½ãã¨ãªã£ããæ¬¡ã¯Packerã§ããããã
Packerã¯åå°ã触ã£ã¦å¤±æãã¦ä»¥æ¥æ¾ç½®ãã¦ããã§
ã©ããã§åææ¦ãã¦ã¿ããã§ããã
ãã¨ã¯ãã§ããBoxã¯Serverspecã§ãã§ãã¯ãããã¨ããã