Chef 安装本地 apt_package 及其依赖项

Chef 安装本地 apt_package 及其依赖项

我尝试在服务器上安装本地烘焙的包:

cookbook_file '/var/cache/apt/archives/nfdhcpd_0.20_all.deb' do
  source 'nfdhcpd_0.20_all.deb'
  owner 'root'
  group 'root'
  mode '0755'
  action :create
end
package 'nfdhcpd_0.20_all.deb' do
    provider Chef::Provider::Package::Dpkg
    source "/var/cache/apt/archives/nfdhcpd_0.20_all.deb"
    action :install
end

我需要使用,dpkg provider因为apt provider不支持本地包(apt package provider cannot handle source attribute. Use dpkg provider instead)。我收到错误(缺少 deps):

STDERR: dpkg: dependency problems prevent configuration of nfdhcpd:
 nfdhcpd depends on python-scapy (>= 2.0.1-1); however:
  Package python-scapy is not installed.

我怎样才能告诉 Chef 安装缺少的依赖项?(无需手动安装)

答案1

dpkg无法安装依赖项,因此您需要创建一个包含您的包的本地 apt 存储库。https://askubuntu.com/a/176546给出了基本思想。您需要将Packages文件与您的放在一起.deb,然后在文件中引用该目录/etc/apt/sources.list.d

file '/etc/apt/sources.list.d/local-apt.list' do
    owner 'root'
    group 'root'
    mode '0644'
    content "deb file:/var/cache/apt/archives/ ./"
    action :create
    notifies :run, 'execute[apt-get update]', :immediately
end

package 'nfdhcpd'

答案2

那么将其-f作为选项传递怎么样?

安装带有选项的包

package 'debian-archive-keyring' do
  action :install
  options '--force-yes'
end

apt_package

apt_package 'name' do
  default_release            String
  notifies                   # see description
  options                    String
  package_name               String, Array # defaults to 'name' if not specified
  provider                   Chef::Provider::Package::Apt
  source                     String
  subscribes                 # see description
  timeout                    String, Integer
  version                    String, Array
  action                     Symbol # defaults to :install if not specified
end

dpkg_软件包

dpkg_package 'name' do
  notifies                   # see description
  options                    String
  package_name               String, Array # defaults to 'name' if not specified
  provider                   Chef::Provider::Package::Dpkg
  source                     String
  subscribes                 # see description
  timeout                    String, Integer
  version                    String, Array
  action                     Symbol # defaults to :install if not specified
end

选项

Ruby 类型:字符串

传递给命令的一个(或多个)附加选项。

相关内容