Right now I have the following in my Vagrantfile:
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = \"cookbooks\"
chef.add_recipe \"apt\"
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