Right now I have the following in my Vagrantfile:
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = \"cookbooks\"
chef.add_recipe \"apt\"
I had the same situation, and in my case, apt cookbook was second after the one which called installation of package. Just leaving it here so maybe someone will benefit from it. Check the order of cookbooks in your runlist, role or wherever else.
apt-get update
should be running first the way you have it. However, the recipe will only update once every 24 hours:
execute "apt-get-update-periodic" do
command "apt-get update"
ignore_failure true
only_if do
File.exists?('/var/lib/apt/periodic/update-success-stamp') &&
File.mtime('/var/lib/apt/periodic/update-success-stamp') < Time.now - 86400
end
end
There are three resources that will do this nicely on an ubuntu system, specifically in use on 12.04 precise 64 bit by me.
run apt-get-update at will when other recipes require
install update-notifier-common package that gives us timestamps on updates
check the timestamps and update periodically. In this case below after 86400 seconds.
And here's those three recipes.
execute "apt-get-update" do
command "apt-get update"
ignore_failure true
action :nothing
end
package "update-notifier-common" do
notifies :run, resources(:execute => "apt-get-update"), :immediately
end
execute "apt-get-update-periodic" do
command "apt-get update"
ignore_failure true
only_if do
File.exists?('/var/lib/apt/periodic/update-success-stamp') &&
File.mtime('/var/lib/apt/periodic/update-success-stamp') < Time.now - 86400
end
end
It looks like the latest version of the opscode apt cookbook allow you to run it at compile time.
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = "cookbooks"
chef.add_recipe "apt"
chef.json = { "apt" => {"compiletime" => true} }
end
As long as apt is run before other compiletime cookbooks (like postgres) in the run list, this should work.
The simplest and most direct way to solve the problem is by applying the following patch (h/t @ashchristopher):
https://github.com/wil/cookbooks/commit/a470a4f68602ec3bf3374830f4990a7e19e9de81
The problem is that the postgresql::client
recipe runs the install action on the package resources at postgresql/recipes/client.rb:39 and 44 at compile-time rather than run-time like normal (h/t Tim Potter), causing them to be evaluated by Chef (and thus installed) before anything else runs.
pg_packages.each do |pg_pack|
package pg_pack do
action :nothing
end.run_action(:install)
end
gem_package "pg" do
action :nothing
end.run_action(:install)
I believe this is done in service of the database cookbook's postgres provider, which depends on the postgresql
cookbook and relies on the pg
gem being installed before it will compile. Applying the above patch may break the database
cookbook.
The other alternative solution would be to create a recipe which runs apt-get update
also at compile time and put it in your run_list
before the postgresql
cookbook. In its simplest form that would probably be something like:
execute "apt-get update" do
action :nothing
end.run_action(:install)
I seem to have been able to solve the issue by applying the following patch:
https://github.com/wil/cookbooks/commit/a470a4f68602ec3bf3374830f4990a7e19e9de81