puppet concat 重复声明
puppet concat Duplicate declaration
我的人偶模块之一出现以下错误:
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
我对 puppet 很陌生,不知道我做错了什么,下面是模块文件:
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 class 被配置调用 class:
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],
}
}
和参数 class:
==> 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 中只配置一个条目时,模块会按预期工作。任何帮助将非常感激。
你的模块应该得到一个 class 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
这个 class 来自您定义的类型。
始终将单例资源(每个节点不能多次声明的东西)放在 classes 中。
我认为问题出在这一行:
concat::fragment { 'autofs::fragment preamble $autofs::params::master':
改为:
concat::fragment { "autofs::fragment preamble ${autofs::params::master}":
您使用了单引号,因此不会评估变量。
有关在 puppet 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}":
我的人偶模块之一出现以下错误:
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
我对 puppet 很陌生,不知道我做错了什么,下面是模块文件:
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 class 被配置调用 class:
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],
}
}
和参数 class:
==> 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 中只配置一个条目时,模块会按预期工作。任何帮助将非常感激。
你的模块应该得到一个 class 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
这个 class 来自您定义的类型。
始终将单例资源(每个节点不能多次声明的东西)放在 classes 中。
我认为问题出在这一行:
concat::fragment { 'autofs::fragment preamble $autofs::params::master':
改为:
concat::fragment { "autofs::fragment preamble ${autofs::params::master}":
您使用了单引号,因此不会评估变量。 有关在 puppet 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}":