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
}

のため、 は 2 回定義されてい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これらの定義に一意の名前を付けずに 2 回宣言した結果です。空の文字列''を 2 回使用します。

編集: が の
場合、とが問題の原因である可能性があります。concat::fragmentdefineconcat::fragment{"hosttemplate":concat::fragment{"servicetemplate":

2 回宣言nagios::iconfすると、puppet はこれらのフラグメントを 2 回宣言しようとします。彼らの名前はユニークではありません。試してみconcat::fragment{"hosttemplate $name":concat::fragment{"servicetemplate $name":

concat{$reconfigure:も! define? 試してみてくださいconcat{"$reconfigure $name":

于 2013-08-28T19:56:29.867 に答える