如何使用puppet APT模块安装varnish服务器

如何使用puppet APT模块安装varnish服务器,puppet,varnish,Puppet,Varnish,我正在尝试使用Puppet和APT模块实现最新版本的varnish服务器,但是,我遇到了一些错误。我需要使用“-强制是”。我该怎么做呢。有人能告诉我我做错了什么或给我举个例子吗。谢谢 这就是我到目前为止所做的 class profile::varnish { notify{'Provisioning varnish server': } include apt apt::key {'apt-key': id => 'E98C6BBBA1CBC5

我正在尝试使用Puppet和APT模块实现最新版本的varnish服务器,但是,我遇到了一些错误。我需要使用“-强制是”。我该怎么做呢。有人能告诉我我做错了什么或给我举个例子吗。谢谢

这就是我到目前为止所做的

class profile::varnish {
    notify{'Provisioning varnish server': }

    include apt

    apt::key {'apt-key':
        id => 'E98C6BBBA1CBC5C3EB2DF21C60E7C096C4DEFFEB',
        source => 'https://repo.varnish-cache.org/GPG-key.txt'
    }

    apt::source {'varnish':
        location => 'https://repo.varnish-cache.org/ubuntu/',
        release => 'trusty',
        repos => 'varnish-4.1',
        require => Apt::Key['apt-key']
    }

    package {'varnish':
        ensure => installed,
        require => Apt::Source['varnish']
    }
}
这里的错误,我与傀儡代理

Error: Execution of '/usr/bin/apt-get -q -y -o DPkg::Options::=--force-confold install varnish' returned 100: Reading package lists...
Building dependency tree...
Reading state information...
The following extra packages will be installed:
  gcc gcc-4.8 libasan0 libatomic1 libc-dev-bin libc6-dev libgcc-4.8-dev
  libitm1 libjemalloc1 libquadmath0 libtsan0 libvarnishapi1 linux-libc-dev
  manpages-dev
Suggested packages:
  gcc-multilib make autoconf automake1.9 libtool flex bison gdb gcc-doc
  gcc-4.8-multilib gcc-4.8-doc gcc-4.8-locales libgcc1-dbg libgomp1-dbg
  libitm1-dbg libatomic1-dbg libasan0-dbg libtsan0-dbg libquadmath0-dbg
  glibc-doc varnish-doc
The following NEW packages will be installed:
  gcc gcc-4.8 libasan0 libatomic1 libc-dev-bin libc6-dev libgcc-4.8-dev
  libitm1 libjemalloc1 libquadmath0 libtsan0 libvarnishapi1 linux-libc-dev
  manpages-dev varnish
0 upgraded, 15 newly installed, 0 to remove and 2 not upgraded.
Need to get 585 kB/12.3 MB of archives.
After this operation, 43.4 MB of additional disk space will be used.
WARNING: The following packages cannot be authenticated!
  libvarnishapi1 varnish
E: There are problems and -y was used without --force-yes

Error: /Stage[main]/Profile::Varnish/Package[varnish]/ensure: change from absent to present failed: Execution of '/usr/bin/apt-get -q -y -o DPkg::Options::=--force-confold install varnish' returned 100: Reading package lists...
Building dependency tree...
Reading state information...
The following extra packages will be installed:
  gcc gcc-4.8 libasan0 libatomic1 libc-dev-bin libc6-dev libgcc-4.8-dev
  libitm1 libjemalloc1 libquadmath0 libtsan0 libvarnishapi1 linux-libc-dev
  manpages-dev
Suggested packages:
  gcc-multilib make autoconf automake1.9 libtool flex bison gdb gcc-doc
  gcc-4.8-multilib gcc-4.8-doc gcc-4.8-locales libgcc1-dbg libgomp1-dbg
  libitm1-dbg libatomic1-dbg libasan0-dbg libtsan0-dbg libquadmath0-dbg
  glibc-doc varnish-doc
The following NEW packages will be installed:
  gcc gcc-4.8 libasan0 libatomic1 libc-dev-bin libc6-dev libgcc-4.8-dev
  libitm1 libjemalloc1 libquadmath0 libtsan0 libvarnishapi1 linux-libc-dev
  manpages-dev varnish
0 upgraded, 15 newly installed, 0 to remove and 2 not upgraded.
Need to get 585 kB/12.3 MB of archives.
After this operation, 43.4 MB of additional disk space will be used.
WARNING: The following packages cannot be authenticated!
  libvarnishapi1 varnish
E: There are problems and -y was used without --force-yes
更新: 对于那些想知道我是如何获得apt::key ID的人,我使用了以下命令

gpg --with-fingerprint your-gpg-key.txt

您需要密钥指纹输出,不带空格。我想与您分享这一点,因为我花了一段时间才弄明白。

不知道这是否是正确的方法,但是,我通过在profile::varnish类中添加以下行成功地解决了这个问题

exec { 'apt-update':
  command => "/usr/bin/apt-get update",
  logoutput => "on_failure",
  path => "/usr/bin:/usr/sbin:/bin:/usr/local/bin:/usr/local/sbin:/sbin",
}

exec { 'apt-upgrade':
  command => "/usr/bin/apt-get --quiet --yes --fix-broken upgrade",
  logoutput => "on_failure",
  path => "/usr/bin:/usr/sbin:/bin:/usr/local/bin:/usr/local/sbin:/sbin",
  require => Exec['apt-update'],
}

您也可以使用apt模块添加gpg密钥

apt::key { 'puppetlabs':
  id      => '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30',
  server  => 'pgp.mit.edu',
  options => 'http-proxy="http://proxyuser:proxypass@example.org:3128"',
}