1
define nagios::iconf( $host_name='', $ip='', $short_alias='',$service_name='',$remote_host_name='',$port=''){
$reconfigure = "/usr/local/nagios/etc/import/${host_name}.cfg"

   concat{$reconfigure:
      owner => nagios,
      group => nagios,
      mode  => 755
   }

   concat::fragment{"hosttemplate":
      target => $reconfigure,
      source => template('nagios/host.erb'),
      order  => 01,
   }

   concat::fragment{"servicetemplate":
      target => $reconfigure,
      ensure  => template("nagios/${service_name}.erb"),
      order   => 15
   }
}
include nagios

当我在 site.pp 中声明时

node "blahblahhostname"{
nagios::iconf{'name1':
  host_name       => 'localhost'
  remote_host_name => 'blahblah1',
  ip      => '32.232.434.323',
  port    => '111',
  short_alias     => 'random',
  service_name    => 'servicename1'
}

nagios::iconf{'name2':
  host_name       => 'localhost'
  remote_host_name => 'blahblah1',
  ip      => '32.232.434.323',
  port    => '111',
  short_alias     => 'random',
  service_name    => 'servicename2'
}
include nagios
}

我收到重复声明错误。我哪里做错了?

4

2 回答 2

1

这里的问题是

concat{"/usr/local/nagios/etc/import/localhost.cfg"
  owner => nagios,
  group => nagios,
  mode  => 755
}

由于 . 被定义了两次host_name。当您define在清单中调用该类型时,它会导致重复警告。

define您必须在类型之外定义一次。可能在一个类中或在其manifests本身中。就像是:

concat{"/usr/local/nagios/etc/import/localhost.cfg"
.....
.....

然后,剩下的代码,即concat::fragments可以进入define类型内部。

define nagios::iconf( $host_name='', $ip='',     $short_alias='',$service_name='',$remote_host_name='',$port=''){
$reconfigure = "/usr/local/nagios/etc/import/${host_name}.cfg"
   concat::fragment{"hosttemplate":
      target => $reconfigure,
      source => template('nagios/host.erb'),
      order  => 01,
   }

   concat::fragment{"servicetemplate":
      target => $reconfigure,
      ensure  => template("nagios/${service_name}.erb"),
      order   => 15
   }
}
于 2013-08-28T20:09:35.400 回答
0

我必须承认,我不确定您在做什么以及您的concat::fragment定义是否也可以工作,但是重复声明错误是由于声明nagios::iconf两次而没有这些定义的唯一名称的结果。''您使用了两次空字符串。

编辑
如果concat::fragmentdefine, 那么concat::fragment{"hosttemplate":并且concat::fragment{"servicetemplate":可能是您的问题的原因。

当声明nagios::iconf两次时,puppet 会尝试两次声明这些片段。他们的名字不是唯一的。尝试concat::fragment{"hosttemplate $name":concat::fragment{"servicetemplate $name":

concat{$reconfigure:也是一个?define!试试concat{"$reconfigure $name":

于 2013-08-28T19:56:29.867 回答