木偶找不到课

时间:2015-08-07 16:25:37

标签: 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

在清单下的superhero.pp下显示代码

class heroes {
    user { 'thor':
        ensure => present,
    }
}

在我的superhero.pp示例中,代码为

include heroes

在错误显示的示例下运行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

1 个答案:

答案 0 :(得分:6)

我认为可能存在两个问题

  1. 首先,当在puppet apply superheroes.pp目录中运行examples时,它不知道在哪里寻找其他模块(例如heroesinclude })。要知道在哪里查找模块,you need to give it a modulepath

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

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

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

      <modulepath>/<module name>/manifests/<subdirectories>.../<file name>.pp
      
    5. 以下是文档中的示例:

          == 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
      

      回到你的问题:在include heroes后,木偶会查看<modulepath>/heroes/manifests/init.pp。相反,要在test/manifests/superhero.pp中查看木偶,您需要添加课程test::superhero

相关问题