Pode estar relacionado à falta de privilégios:
$ 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
Quando eu joguei com o chef, usei isso:
# 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
Eu incluí isso nas minhas receitas, por exemplo, 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