解决冲突的包资源声明

时间:2014-04-17 16:02:16

标签: puppet

我们正在尝试使用camptocamp/puppet-nagios模块,但我们遇到了vanilla CentOS存储库和RPMForge/RepoForge之间的打包命名冲突。 CentOS中的nsca守护程序提供与RepoForge中nagios-nsca程序包相同的服务。在尝试安装RepoForge包但仍满足Package资源的nsca要求时,我已将此添加到我的节点定义中:

    include ::nagios
    package { 'nagios-nsca': ensure => installed, alias => 'nsca', }
    include ::nagios::nsca::server

产生的错误是:

    Error: Duplicate declaration: Package[nsca] is already declared in
    file /tmp/vagrant-puppet-1/modules-0/role/manifests/nagios.pp:45;
    cannot redeclare at
    /tmp/vagrant-puppet-1/modules-2/nagios/manifests/nsca/server.pp:24

下一个测试是使用顺序并直接从节点调用class

    include ::nagios
    package { 'nagios-nsca': ensure => installed, alias => 'nsca', } -> 
    class {'::nagios::nsca::server' : }

nagios/manifests/nsca/server.pp文件中的相关代码是:

    class nagios::nsca::server(
      $decryption_method = pick($nagios_nsca_decryption_method, '0'),
    ) {

      include ::nagios::params

      # variables used in ERB template
      $basename = $nagios::params::basename

      if !defined (Package['nsca']) {
        package {'nsca':
          ensure => installed;
        }
      }

有关此处发生的事情的任何见解?我总是可以分叉camptocamp/puppet-nagios代码并强制我们想要的行为,但我不愿意。

1 个答案:

答案 0 :(得分:2)

由于! defined(Package['title'])未按预期工作。我通过为nagios::nsca::server提供nsca_package的附加参数来修复此问题,包括默认值nsca以保留当前行为:

    --- a/manifests/nsca/server.pp
    +++ b/manifests/nsca/server.pp
    @@ -11,6 +11,7 @@
     #
     class nagios::nsca::server(
       $decryption_method = pick($nagios_nsca_decryption_method, '0'),
    +  $nsca_package = 'nsca'
     ) {

       include ::nagios::params
    @@ -20,6 +21,7 @@ class nagios::nsca::server(

       if !defined (Package['nsca']) {
         package {'nsca':
    +      name => $nsca_package,
           ensure => installed;
         }
       }

这个新参数的用途是:

    node 'my-nagios-server.local' {
      include ::nagios
      class {'::nagios::nsca::server': nsca_package => 'nagios-nsca', }
    }