如何在puppet中使用concat将两个文件合并到同一个文件中?

如何在puppet中使用concat将两个文件合并到同一个文件中?,puppet,Puppet,当我在site.pp中声明 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

当我在site.pp中声明

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

我得到重复声明错误。我哪里出错了?

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

编辑
如果
concat::fragment
define
,那么
concat::fragment{“hosttemplate”:
concat::fragment{“servicemplate”:
可能是问题的原因

当两次声明
nagios::iconf
时,puppet会尝试两次声明这些片段。它们的名称不唯一。请尝试
concat::fragment{“hosttemplate$name”:
concat::fragment{“servicetemplate$name”:


concat{$reconforme:
也是一个
define
?试试
concat{“$reconforme$name”:

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

编辑
如果
concat::fragment
define
,那么
concat::fragment{“hosttemplate”:
concat::fragment{“servicemplate”:
可能是问题的原因

当两次声明
nagios::iconf
时,puppet会尝试两次声明这些片段。它们的名称不唯一。请尝试
concat::fragment{“hosttemplate$name”:
concat::fragment{“servicetemplate$name”:

concat{$reconforme:
也是一个
define
?试试
concat{“$reconforme$name”:

这里的问题是

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
}
由于
主机名
而定义了两次。在清单中调用
定义
类型时,会导致重复警告

您只需在
define
类型之外定义一次。可能在类中或
manifests
本身中。类似于:

concat{"/usr/local/nagios/etc/import/localhost.cfg"
  owner => nagios,
  group => nagios,
  mode  => 755
}
然后,其余的代码,即
concat::fragments
可以进入
define
类型中

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

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
}
由于
主机名
而定义了两次。在清单中调用
定义
类型时,会导致重复警告

您只需在
define
类型之外定义一次。可能在类中或
manifests
本身中。类似于:

concat{"/usr/local/nagios/etc/import/localhost.cfg"
  owner => nagios,
  group => nagios,
  mode  => 755
}
然后,其余的代码,即
concat::fragments
可以进入
define
类型中

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

您可以发布您得到的确切错误吗?错误:无法从远程服务器检索目录:服务器上的错误400:重复声明:Concat[/usr/local/nagios/etc/import/localhost.cfg]已在文件/etc/puppet/modules/nagios/manifests/iconf.pp的第9行声明;无法在节点上重新声明为什么要声明
nagios::iconf{'
两次?在这两种情况下是否给出了两个不同的
host\u name
host\u name
决定了
concat::fragments
的名称,这可能会导致问题。有两个不同的服务名..其他所有内容都是一样的。我已经为这个问题添加了一个答案。看看它是否有帮助。你能发布准确的错误吗错误:无法从远程服务器检索目录:服务器上的错误400:重复声明:Concat[/usr/local/nagios/etc/import/localhost.cfg]已在文件/etc/puppet/modules/nagios/manifests/iconf.pp的第9行声明;无法在节点上重新声明为什么要声明
nagios::iconf{'
两次?在这两种情况下是否给出了两个不同的
host\u name
host\u name
决定了
concat::fragments
的名称,这可能会导致问题。有两个不同的服务名..其他所有内容都是相同的。我已经为问题添加了一个答案。看看是否有帮助。我从空中删除了信息字符串。我不确定这一点,因为你可以为nagios::iconf使用空参数(当然,除了define的名称),我从空字符串中删除了信息。我不确定这一点,因为你可以为nagios::iconf使用空参数(当然,除了define的名称)你是对的。我在define类型之外声明过一次。在一个类中,结果很好。你是对的。我在define类型之外声明过一次。在一个类中,结果很好。