Puppet 木偶找不到类

Puppet 木偶找不到类,puppet,Puppet,您好,我是puppet新手,我正在尝试创建一个测试类,但是当我运行puppet apply-t时,我得到错误error:Evaluation error:error在计算函数调用时,找不到的类::heros 在我的测试目录下,我有 . ├── examples │   ├── init.pp │   └── superhero.pp └── manifests ├── init.pp └── superhero.pp 2 directories, 4 files 在我的sup

您好,我是puppet新手,我正在尝试创建一个测试类,但是当我运行
puppet apply-t
时,我得到错误
error:Evaluation error:error在计算函数调用时,找不到的类::heros
在我的测试目录下,我有

.
├── examples
│   ├── init.pp
│   └── superhero.pp
└── manifests
    ├── init.pp
    └── superhero.pp

2 directories, 4 files
在我的
superhero.pp
清单下,代码读取

class heroes {
    user { 'thor':
        ensure => present,
    }
}
include heroes
在我的
superhero.pp
示例中,代码如下

class heroes {
    user { 'thor':
        ensure => present,
    }
}
include heroes
不知道为什么在出现错误的示例下运行
puppet apply--noop superheros.pp

这是我在模块下的完整树

├── hosts
│   ├── examples
│   │   └── init.pp
│   └── manifests
│       └── init.pp
├── nginx
│   ├── examples
│   │   └── init.pp
│   ├── files
│   │   ├── default.conf
│   │   ├── index.html
│   │   └── nginx.conf
│   ├── index.html
│   └── manifests
│       ├── index.html
│       └── init.pp
├── test
│   ├── examples
│   │   ├── admins.pp
│   │   ├── init.pp
│   │   └── superhero.pp
│   └── manifests
│       ├── admins.pp
│       ├── init.pp
│       └── superhero.pp
└── users
├── examples
│   ├── admins.pp
│   └── init.pp
└── manifests
    ├── admins.pp
    └── init.pp

我认为可能有两个问题

  • 首先,当运行
    examples
    目录中的
    puppet apply superheros.pp
    时,它不知道在哪里可以找到其他模块(比如
    heros
    包含的
    )。要知道在何处查找模块,请执行以下操作:

    puppet apply--modulepath=/path/to/modules--noop superhero.pp

  • 另一个问题是您声明的
    英雄
    类位于
    test/manifests/superhero.pp
    中的位置。描述了Puppet试图查找类的位置规则,并给出了详细说明。除非您正在做一些不太常见的事情,例如在另一个类中定义一个类,否则puppet将使用以下规则定位该类:

  • 第一段(段由
    分隔)标识模块
  • 如果只有一个段,则文件名为
    init.pp
    ,否则文件名为扩展名为
    .pp
    的最后一个段
  • 中间的段表示
    清单
    目录下的子目录
  • 木偶将看到的路径是

    <modulepath>/<module name>/manifests/<subdirectories>.../<file name>.pp
    
    //清单/../.pp
    
  • 以下是文档中的一个示例:

        == class name ==        == path ==
        apache                  <module path>/apache/manifests/init.pp
        apache::mod             <module path>/apache/manifests/mod.pp
        apache::mod::passenger  <module path>/apache/manifests/mod/passenger.pp
    
    ==类名===路径==
    apache/apache/manifests/init.pp
    apache::mod/apache/manifests/mod.pp
    apache::mod::passenger/apache/manifests/mod/passenger.pp
    

  • 回到你的问题:在
    包含英雄
    时,木偶将查看
    /heros/manifests/init.pp
    。相反,要让puppet在
    test/manifests/superhero.pp
    中查看,您需要包含class
    test::superhero

    如果您想让自动加载程序找到您的类并允许您
    包含它,您应该将它放在一个模块中。请看我的模块(examples superhero.pp)中是否包含我的内容?不,模块位于
    模块/
    下,例如
    模块/英雄/清单/超级英雄.pp
    ,然后您可以从其他地方
    包含英雄::超级英雄。(还要确保根据模块/文件名为类命名-
    英雄/manifests/superheros.pp
    将是
    类英雄::超级英雄{}
    。现在非常感谢。puppet将您的资源转移到了您身上,您能更新链接吗?