vagrantとchefを使うときの注意点 (1)

ふつう/tmpはtmpfsにしたいと思ってこういうrecipeを書くじゃないですかーやだなーもう。

mount "/tmp" do
  pass 0
  fstype "tmpfs"
  device "none"
  action [:mount, :enable]
end

それをVagrantで操作しているVMに適用するような操作をすると、cookbookが見つからないとかいうエラーが出るじゃないですかー。

Bringing machine 'default' up with 'virtualbox' provider...
[default] Importing base box 'cent64'...
[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] Clearing any previously set network interfaces...
[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22 => 2200 (adapter 1)
[default] Running 'pre-boot' VM customizations...
[default] Booting VM...
[default] Waiting for machine to boot. This may take a few minutes...
DL is deprecated, please use Fiddle
[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
prevent things such as shared folders from working properly. If you see
shared folder errors, please make sure the guest additions within the
virtual machine match the version of VirtualBox you have installed on
your host and reload your VM.

Guest Additions Version: 4.2.16
VirtualBox Version: 4.3
[default] Mounting shared folders...
[default] -- /vagrant
[default] -- /tmp/vagrant-cache
[default] -- /tmp/vagrant-chef-1/chef-solo-1/cookbooks
[default] Running provisioner: chef_solo...
[default] Configuring cache buckets...
Generating chef JSON and uploading...
Running chef-solo...
[2014-01-24T14:08:47+00:00] INFO: Forking chef instance to converge...
[2014-01-24T14:08:47+00:00] INFO: *** Chef 11.6.0 ***
[2014-01-24T14:08:48+00:00] INFO: Setting the run_list to ["recipe[base::tmpfs]", "recipe[base::ntp]", "recipe[base::timezone]", "recipe[base::epel]"] from JSON
[2014-01-24T14:08:48+00:00] INFO: Run List is [recipe[base::tmpfs], recipe[base::ntp], recipe[base::timezone], recipe[base::epel]]
[2014-01-24T14:08:48+00:00] INFO: Run List expands to [base::tmpfs, base::ntp, base::timezone, base::epel]
[2014-01-24T14:08:48+00:00] INFO: Starting Chef Run for localhost
[2014-01-24T14:08:48+00:00] INFO: Running start handlers
[2014-01-24T14:08:48+00:00] INFO: Start handlers complete.
[2014-01-24T14:08:48+00:00] WARN: Cloning resource attributes for service[ntpdate] from prior resource (CHEF-3694)
[2014-01-24T14:08:48+00:00] WARN: Previous service[ntpdate]: /tmp/vagrant-chef-1/chef-solo-1/cookbooks/base/recipes/ntp.rb:21:in `block in from_file'
[2014-01-24T14:08:48+00:00] WARN: Current  service[ntpdate]: /tmp/vagrant-chef-1/chef-solo-1/cookbooks/base/recipes/ntp.rb:27:in `block in from_file'
[2014-01-24T14:08:48+00:00] WARN: Cloning resource attributes for service[ntpd] from prior resource (CHEF-3694)
[2014-01-24T14:08:48+00:00] WARN: Previous service[ntpd]: /tmp/vagrant-chef-1/chef-solo-1/cookbooks/base/recipes/ntp.rb:21:in `block in from_file'
[2014-01-24T14:08:48+00:00] WARN: Current  service[ntpd]: /tmp/vagrant-chef-1/chef-solo-1/cookbooks/base/recipes/ntp.rb:27:in `block in from_file'
[2014-01-24T14:08:48+00:00] WARN: Cloning resource attributes for execute[rpmkey] from prior resource (CHEF-3694)
[2014-01-24T14:08:49+00:00] INFO: mount[/tmp] mounted
[2014-01-24T14:08:49+00:00] INFO: mount[/tmp] enabled

================================================================================
Error executing action `install` on resource 'yum_package[ntp]'
================================================================================


Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '1'
---- Begin output of /usr/bin/python /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/provider/package/yum-dump.py --options --installed-provides ----
STDOUT: [option installonlypkgs] kernel kernel-bigmem installonlypkg(kernel-module) installonlypkg(vm) kernel-enterprise kernel-smp kernel-debug kernel-unsupported kernel-source kernel-devel kernel-PAE kernel-PAE-debug
STDERR: yum-dump Repository Error: Error making cache directory: /var/cache/yum/x86_64/6/base error was: [Errno 2] No such file or directory: '/var/cache/yum/x86_64'
---- End output of /usr/bin/python /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/provider/package/yum-dump.py --options --installed-provides ----
Ran /usr/bin/python /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.6.0/lib/chef/provider/package/yum-dump.py --options --installed-provides returned 1


Resource Declaration:
---------------------
[2014-01-24T14:08:50+00:00] INFO: Running queued delayed notifications before re-raising exception
[2014-01-24T14:08:50+00:00] ERROR: Running exception handlers
[2014-01-24T14:08:50+00:00] ERROR: Exception handlers complete
[2014-01-24T14:08:50+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.

Vagrantはcookbookやキャッシュを/tmp以下にマウントするんですよね。だからcookbookの中で/tmpをマウントしてカラにしたらcookbookのファイルが読めなくなってダメなんですな。actionからmountを外せば問題は解消しますが、/tmpがtmpfsになるのはリブート後ということになります。

Fedoraの最近のは/tmpがやっとtmpfsになったし、こんなrecipeもそのうち不要になりますね。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です