Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get Chef to run apt-get update before running other recipes

Right now I have the following in my Vagrantfile:

config.vm.provision :chef_solo do |chef|     chef.cookbooks_path = "cookbooks"     chef.add_recipe "apt"     chef.add_recipe "build-essential"     chef.add_recipe "chef-redis::source"     chef.add_recipe "openssl"     chef.add_recipe "git"     chef.add_recipe "postgresql::server"     chef.add_recipe "postgresql::client" end 

In order to install the software added to my recipe_list, I need to get the VM to issue an apt-get update before installing the other software.

I was under the impression that this was one of the features of the 'apt' recipe - that it would run the update first thing.

The output when I do a vagrant provision is:

[Sat, 11 Feb 2012 22:20:03 -0800] INFO: *** Chef 0.10.2 *** [Sat, 11 Feb 2012 22:20:03 -0800] INFO: Setting the run_list to ["recipe[apt]", "recipe[build-essential]", "recipe[chef-redis::source]", "recipe[openssl]", "recipe[git]", "recipe[postgresql::server]", "recipe[postgresql::client]", "recipe[vagrant-main]"] from JSON [Sat, 11 Feb 2012 22:20:03 -0800] INFO: Run List is [recipe[apt], recipe[build-essential], recipe[chef-redis::source], recipe[openssl], recipe[git], recipe[postgresql::server], recipe[postgresql::client], recipe[vagrant-main]] [Sat, 11 Feb 2012 22:20:03 -0800] INFO: Run List expands to [apt, build-essential, chef-redis::source, openssl, git, postgresql::server, postgresql::client, vagrant-main] [Sat, 11 Feb 2012 22:20:03 -0800] INFO: Starting Chef Run for lucid32 [Sat, 11 Feb 2012 22:20:03 -0800] INFO: Processing package[postgresql-client] action install (postgresql::client line 37) [Sat, 11 Feb 2012 22:20:04 -0800] ERROR: package[postgresql-client] (postgresql::client line 37) has had an error [Sat, 11 Feb 2012 22:20:04 -0800] ERROR: Running exception handlers [Sat, 11 Feb 2012 22:20:04 -0800] ERROR: Exception handlers complete [Sat, 11 Feb 2012 22:20:04 -0800] FATAL: Stacktrace dumped to /tmp/vagrant-chef-1/chef-stacktrace.out [Sat, 11 Feb 2012 22:20:04 -0800] FATAL: Chef::Exceptions::Exec: package[postgresql-client] (postgresql::client line 37) had an error: apt-get -q -y install postgresql-client=8.4.8-0ubuntu0.10.04 returned 100, expected 0 
like image 273
ashchristopher Avatar asked Feb 12 '12 05:02

ashchristopher


People also ask

Which programming language is used by chef to execute the recipes?

Chef uses Ruby as its reference language to define the patterns that are found in resources, recipes, and cookbooks. Use these patterns to configure, deploy, and manage nodes across the network.

What is chef client cookbook?

This cookbook is used to configure a system to run the Chef Infra Client.


2 Answers

You can include the apt recipe in the very beginning:

include_recipe 'apt' 

this will run the update command.

like image 130
rtacconi Avatar answered Sep 22 '22 06:09

rtacconi


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 
like image 21
Ivy Evans Avatar answered Sep 21 '22 06:09

Ivy Evans