Puppet manifest 有一个文件声明,它以某种方式复制了自己 [英] Puppet manifest has a file declaration that somehow duplicates itself

查看:38
本文介绍了Puppet manifest 有一个文件声明,它以某种方式复制了自己的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于令人困惑的错误消息:

Given the confusing error message:

错误:无法从远程服务器检索目录:错误 400服务器:重复声明:文件 [/etc/logstash/conf.d] 已经存在在文件中声明/var/lib/puppet/envs/SYS_15378/modules/logstash/manifests/config.pp at第 54 行;不能重新申报/var/lib/puppet/envs/SYS_15378/modules/logstash/manifests/config.pp:54在节点 foo.bar.com 上

err: Could not retrieve catalog from remote server: Error 400 on SERVER: Duplicate declaration: File[/etc/logstash/conf.d] is already declared in file /var/lib/puppet/envs/SYS_15378/modules/logstash/manifests/config.pp at line 54; cannot redeclare at /var/lib/puppet/envs/SYS_15378/modules/logstash/manifests/config.pp:54 on node foo.bar.com

问题:

  • 如果这真的是在复制文件,我该如何调试(查找文件)?
  • 如果不是……这实际上是在交流什么?

注意:

  • 重复声明在第 54 行
  • 它正在复制的文件定义在...第 54 行
  • 第 54 行与第 54 行相同

有问题的行是右大括号:

The line in question is the closing brace of:

file { "${logstash::params::config_dir}":
   ensure  => directory,
   owner   => root,
   group   => root,
   mode    => '0755',
   purge   => true,
}

哪里

class logstash::params {
 $config_dir = '/etc/logstash/conf.d'
  ...
}

推荐答案

定义类型不应声明公共资源,即不是从 define 实例 $name 派生的>.

Defined types should not declare common resources, meaning such that are not derived from the define instances $name.

在您的示例中,目录是您的 define 的许多实例需要的资源.因此,它应该转移到(可能是专门的)班级.

In your example, the directory is a resource that many instances of your define need. It should therefor move to a (perhaps dedicated) class.

class logstash::config_dir {
    file { "${logstash::params::config_dir}":
        ensure  => directory,
        owner   => root,
        group   => root,
        mode    => '0755',
        purge   => true,
    }
}

在你的define中,你只需

include logstash::config_dir

多次包含一个类不会带来任何问题,并且可以完全解决该问题(以及其他问题).

Including a class multiple times poses no problem and solves exactly that problem (among others).

这篇关于Puppet manifest 有一个文件声明,它以某种方式复制了自己的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆