2

I'm running Chef solo (version 11.4.0) on a clean VPS with Ubuntu 12 installed, and I'm having some problems with apt. The problem was that any package command raised an error:

Chef::Exceptions::Exec
----------------------
apt-get -q -y install update-notifier-common=0.126 returned 100, expected 0

But, running that command on the shell worked perfectly.

After investigating it for a while I found that people recommended to run Opscode apt cookbook (version 1.9.0) in the run list before any cookbook. That way, some problems with apt-get update cache were solved.

So I put in my run list the cookbook apt first, and I'm still having the same errors:

Recipe: apt::default
* execute[apt-get-update] action run
  - execute apt-get update
* execute[apt-get update] action nothing (up to date)
* execute[apt-get autoremove] action nothing (up to date)
* execute[apt-get autoclean] action nothing (up to date)
* package[update-notifier-common] action install

================================================================================
Error executing action `install` on resource 'package[update-notifier-common]'
================================================================================

Chef::Exceptions::Exec
----------------------
apt-get -q -y install update-notifier-common=0.126 returned 100, expected 0

Resource Declaration:
---------------------
# In /home/ubuntu/.chef/toldo-cookbooks/cookbooks/apt/recipes/default.rb

 48: package "update-notifier-common" do
 49:   notifies :run, resources(:execute => "apt-get-update"), :immediately
 50: end
 51:

Compiled Resource:
------------------
# Declared in /home/ubuntu/.chef/toldo-cookbooks/cookbooks/apt/recipes/default.rb:48:in `from_file'

package("update-notifier-common") do
  action :install
  retries 0
  retry_delay 2
  package_name "update-notifier-common"
  version "0.126"
  cookbook_name :apt
  recipe_name "default"
end

[2013-02-24T19:31:10+00:00] ERROR: Running exception handlers
[2013-02-24T19:31:10+00:00] ERROR: Exception handlers complete
Chef Client failed. 1 resources updated
[2013-02-24T19:31:10+00:00] FATAL: Stacktrace dumped to /home/ubuntu/.chef/toldo-cookbooks/chef-stacktrace.out
[2013-02-24T19:31:10+00:00] FATAL: Chef::Exceptions::Exec: package[update-notifier-common] (apt::default line 48) had an error: Chef::Exceptions::Exec: apt-get -q -y install update-notifier-common=0.126 returned 100, expected 0

Do you have some clue from where I can continue my investigation?

Many thanks!

blat
  • 23
  • 1
  • 4

1 Answers1

1

It may be related to lack of privileges:

$ id
uid=1000(gaizka)
$ apt-get install vim # Just kidding!
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
$ echo $?
100

When I played with chef I used this:

# Usage:
# Chef::Provider::Package::Apt.send(:include, CustomApt::UseSudo)

module CustomApt
  module UseSudo
    def self.included(base)
      base.class_eval do

        alias_method :install_package_without_sudo, :install_package
        def install_package(name, version)
          package_name = "#{name}=#{version}"
          package_name = name if @is_virtual_package
          run_command_with_systems_locale(
            :command => "sudo apt-get -q -y#{expand_options(@new_resource.options)} install #{package_name}",
            :environment => {
              "DEBIAN_FRONTEND" => "noninteractive"
            }
            )
        end
      end
    end
  end
end

I included that in my recipes, i.e. install_packages.rb:

# So we install packages with sudo
Chef::Provider::Package::Apt.send(:include, CustomApt::UseSudo)

include_recipe "imagemagick::devel"

node['application']['install_packages'].each do |package_name|
  package package_name do
    action :install
  end
end
Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
gaizka
  • 126
  • 1
  • you were right. It seems like a permission problem. I'm updating the way I run the cookbooks to do it as root. – blat Mar 03 '13 at 11:14