puppet concat重复声明

时间:2015-06-02 14:07:19

标签: puppet

我从其中一个木偶模块中收到以下错误:

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Duplicate declaration: Concat[/etc/auto.master] is already declared in file /etc/puppetlabs/puppet/environments/development/modules/autofs/manifests/mount.pp:16; cannot redeclare at /etc/puppetlabs/puppet/environments/development/modules/autofs/manifests/mount.pp:16 on node nbsrvadm-02v.diasemi.com

我对木偶很新,不知道我做错了什么,下面是模块文件:

Init.pp

class autofs ($master=$autofs::params::master) inherits autofs::params {
  concat { "$master":
    owner  => 'root',
    group  => 'root',
    mode   => '0644',
    notify => Service[$autofs::params::service],
  }
  anchor { 'autofs::begin': }
  class { 'autofs::install': } ->
  class { 'autofs::config': } ~>
  class { 'autofs::service': }
  anchor { 'autofs::end': }
}

mount.pp类由config类调用:

 class autofs::config {
  $map_options = hiera('mapOptions')
  create_resources( 'autofs::mount', $map_options)
}

然后mount.pp如下所示:

define autofs::mount (
  $mount,
  $mapfile,
  $options,
  $order,
) {
  include autofs::params

  concat::fragment { 'autofs::fragment preamble $autofs::params::master':
    ensure  => present,
    target  => "$autofs::params::master",
    content => "${mount} ${mapfile}.$::site_shortname ${options} \n",
    order   => $order,
  }

  file { $mount:
    ensure => directory,
  }

  file { "${mapfile}.$::site_shortname":
    ensure  => link,
    target => "/usr/share/centrifydc/etc/adauto.pl",
    notify  => Service[$autofs::params::service],
  }

}

和params课程:

==> params.pp <==

class autofs::params {

  case $::operatingsystem {
     RedHat: {
       case $::operatingsystemmajrelease {
         5: {
              $package_version="5.0.1-0.rc2.184.el5"
           }
         6: {
              $package_version="5.0.5-109.el6_6.1"
           }
         default: {
              fail("Module ${module_name} is not supported on ${::operatingsystem} version ${::operatingsystemmajrelease}")
           }
         }
           $master="/etc/auto.master"
           $service="autofs"
           $package="autofs"
           $hasrestart="true"
           $hasstatus="true"
      }
     default: {
       fail("Module ${module_name} is not supported on ${::operatingsystem}")
      }
   }
}

最后是hiera中的数据:

---
classes:
  - autofs
mapOptions:
  archived:
    mount: '/archived'
    mapfile: '/etc/auto.archived'
    options: 'ro,defaults,_netdev,tcp'
    order: 01
  cad:
    mount: '/cad'
    mapfile: '/etc/auto.cad'
    options: 'defaults,_netdev,tcp'
    order: 02

当只在hiera中配置一个条目时,模块按预期工作。任何帮助将非常感激。

2 个答案:

答案 0 :(得分:1)

我认为问题在于这一行:

concat::fragment { 'autofs::fragment preamble $autofs::params::master':

将其更改为:

concat::fragment { "autofs::fragment preamble ${autofs::params::master}":

您使用了单引号,因此变量将进行评估。 更多关于在傀儡here中引用的内容。

<强>更新

另一个问题 - 您从未更改$autofs::params::master的值。 这就是为什么每次创建autofs::mount对象的实例时,它都将包含

的实例
Concat::Fragment ["autofs::fragment preamble /etc/auto.master"] 

autofs::params::master更改为每个autofs::mount实际不同的变量,例如:

concat::fragment { "autofs::fragment preamble ${mount}":

答案 1 :(得分:0)

如果模块尚未拥有,则应该获得一个类autofs。将concat资源移到那里。

class autofs($master=$autofs::params::master) inherits autofs::params {
  concat { "$master":
    owner  => 'root',
    group  => 'root',
    mode   => '0644',
    notify => Service[$autofs::params::service],
  }
}

您可以从定义的类型中include这个类。

始终在类中放置单例资源(每个节点不得多次声明的内容)。