找不到类,但它在那里

sys*_*138 32 puppet puppetmaster

puppet agent从新图像进行调用时,出现err: Could not find class custommod错误。该模块本身/etc/puppet/modules/custommod与我们正在调用的所有其他模块相同,但这个模块是顽固的。

[网站.pp]

node /clunod-wk\d+\.sub\.example\.local/ {
      include base
      include curl
      include custommod
      class{ "custommod::apps": frontend => "false}
      [...]
}
Run Code Online (Sandbox Code Playgroud)

当 puppetmaster 以调试输出运行时,它清楚地找到了 base 和 curl 的信息:

debug: importing '/etc/puppet/modules/base/manifests/init.pp' in environment production
debug: Automatically imported base from base into production
debug: importing '/etc/puppet/modules/curl/manifests/init.pp' in environment production
debug: Automatically imported curl from curl into production
err: Could not find class custommod for clunod-wk0130.sub.example.local at /etc/puppet/manifests/site.pp:84 on node clunod-wk0130.sub.example.local
Run Code Online (Sandbox Code Playgroud)

第 84 行是 include custommod

一个简略的目录和文件结构:

/etc/puppet
   |- manifests
   |     |- site.pp
   |
   |- modules
         |- base
         |    |- manifests
         |          |- init.pp
         |
         |- curl
         |    |- manifests
         |          |- init.pp
         |   
         |- custommod
              |- files 
              |     |- apps
              |         |- [...]
              |
              |- manifests
                    |- init.pp
                    |- apps.pp
Run Code Online (Sandbox Code Playgroud)

我确实检查了拼写:}

含量init.pp在custommod目录是完全不值一提:

class custommod {
}
Run Code Online (Sandbox Code Playgroud)

目的是为 apps.pp 文件创建一个空类,这是肉所在的位置。

class custommod::apps {

    [lots of stuff]
}
Run Code Online (Sandbox Code Playgroud)

只是,它永远不会进入应用程序文件。如果我注释掉include custommod,则会class{ "custommod::apps": frontend => "false}在行上生成上述错误。

我在寻找这个错误是如何产生的过程中遗漏了什么?我需要注意的是,如果它通过puppet apply.

sys*_*138 33

所以……这有点尴尬,但是……

环境。

在我的/etc/puppet.conf文件中是这样的:

[master]
  manifest=$confdir/manifests/site.pp
  modulepath=$confdir/environments/$environment/modules:$confdir/modules
Run Code Online (Sandbox Code Playgroud)

在抛出strace它以找出它正在寻找文件的位置后,我注意到了一些事情。它一直在寻找custommod下/etc/puppet/environments/production/modules,由于有一个目录下有(空),它没有然后去检查/etc/puppet/modules。显然,在导入模块时,它会检查目录存在,而不是文件存在 (init.pp)。

删除那个空目录,事情开始工作。

使用不同的环境运行 puppet 代理,一切开始工作。

故事的道德启示:

Puppet 环境路径不像 bash $PATH。

  • 如果有人没有在 puppet.conf 中明确定义他们的模块路径,并且他们想在不求助于 strace 的情况下找出 puppet 的模块路径,他们也可以运行 `puppet config print modulepath`。 (9认同)
  • 模块路径现在会触发弃用警告。 (3认同)

spu*_*der 6

我遇到了同样的问题,但有不同的解决方案

如果您生成像这样的木偶模块:

puppet module generate foo-example_module
Run Code Online (Sandbox Code Playgroud)

它将创建一个以example_module名称foo空间命名的模块。所有清单都将位于名为的目录中foo-example_module

init.pp 中定义的类名称需要与文件夹名称相同。

简单修复:

mv foo-example_module example_module
Run Code Online (Sandbox Code Playgroud)

如果您运行 puppet-lint,它将发出警告并显示以下消息:

ERROR: example_module not in autoload module layout on line 42
Run Code Online (Sandbox Code Playgroud)

如果将 Puppetfile 与 r10k 或 librarian-puppet 一起使用,您可能还需要删除名称空间,以便将文件放置在模块目录中而不带“foo”前缀。

前:

mod 'foo-example_module',
    :git => git@github.com:foo/example_module'
Run Code Online (Sandbox Code Playgroud)

后:

mod 'example_module',
    :git => git@github.com:foo/example_module'
Run Code Online (Sandbox Code Playgroud)