木偶找不到课

jum*_*947 1 puppet

嗨,我是木偶的新手,我正在尝试制作一个测试类,但是当我运行时,我在我的测试目录下puppet apply-t得到错误Error: Evaluation Error: Error while evaluating a Function Call, Could not find class ::heroes

.
??? examples
?   ??? init.pp
?   ??? superhero.pp
??? manifests
    ??? init.pp
    ??? superhero.pp

2 directories, 4 files
Run Code Online (Sandbox Code Playgroud)

在我的superhero.pp下面清单代码读取

class heroes {
    user { 'thor':
        ensure => present,
    }
}
Run Code Online (Sandbox Code Playgroud)

在我的superhero.pp示例下,代码读取

include heroes
Run Code Online (Sandbox Code Playgroud)

不确定为什么当我puppet apply --noop superheroes.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
Run Code Online (Sandbox Code Playgroud)

Mif*_*eet 6

我想可能有两个问题

  1. 首先,当puppet apply superheroes.ppexamples目录中运行时,它不知道在哪里寻找其他模块(像heroes你一样include).要知道在哪里查找模块,您需要为其提供模块路径:

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

  2. 另一个问题是heroes您声明的类所在的位置test/manifests/superhero.pp.Puppet试图找到类的规则在这里这里描述.除非你做一些不太常见的事情,比如在另一个类中定义一个类,puppet将使用以下规则来定位该类:

    1. 第一个段(段由分隔::)标识模块.
    2. 如果只有一个段,则文件名为init.pp,否则文件名是具有.pp扩展名的最后一个段
    3. 其间的段表示目录下的manifests子目录.
    4. 木偶看起来的路径是

      <modulepath>/<module name>/manifests/<subdirectories>.../<file name>.pp
      
      Run Code Online (Sandbox Code Playgroud)

    以下是文档中的示例:

        == 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
    
    Run Code Online (Sandbox Code Playgroud)

回到你的问题:include heroes傀儡会看到<modulepath>/heroes/manifests/init.pp.相反,为了让木偶看起来test/manifests/superhero.pp,你需要包括课程test::superhero.

  • puppet 把你的资源转移到你身上了,你能更新一下链接吗? (2认同)