找不到课程,但它在那里

当从一个新的图像做puppet agent电话,我得到一个err: Could not find class custommod错误。 模块本身在/etc/puppet/modules/custommod与我们调用的所有其他模块相同,但是这个模块是obstinante。

[site.pp]

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

当puppetmaster运行debugging输出时,它清楚地发现了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 

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 

我没有检查拼写:}

custommod目录中init.pp的内容完全不起作用:

 class custommod { } 

目的是为apps.pp文件创build一个空的类,这是肉的地方。

 class custommod::apps { [lots of stuff] } 

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

我在寻找什么,以找出如何产生这个错误? 我需要注意的是,如果通过puppet apply在本地运行,这个回购工作得很好。

所以…这有点尴尬,但…

环境。

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

 [master] manifest=$confdir/manifests/site.pp modulepath=$confdir/environments/$environment/modules:$confdir/modules 

把它放在strace找出它在寻找文件的位置后,我注意到了一些东西。 它正在/etc/puppet/environments/production/modules下查找custommod,因为那里有一个目录(空的), 所以没有检查/etc/puppet/modules 。 显然,在导入模块时,它会检查目录存在,而不是文件存在(init.pp)。

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

使用不同的环境运行木偶代理,事情开始工作。

故事的道德启示:

Puppet环境path不像bash $ PATH。

我遇到了同样的问题,但有一个不同的修复

如果你这样生成一个puppet模块:

 puppet module generate foo-example_module 

它将使用foo名称空间创build一个名为example_module的模块。 所有的清单将在一个名为foo-example_module的目录中

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

简单的修复:

 mv foo-example_module example_module 

如果你运行puppet-lint,它会警告以下消息:

 ERROR: example_module not in autoload module layout on line 42 

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

之前:

 mod 'foo-example_module', :git => [email protected]:foo/example_module' 

后:

 mod 'example_module', :git => [email protected]:foo/example_module' 

另一个可能发生的问题是当你的模块有一个无效的metadata.json文件。

确保metadata.json文件具有所有必填字段(请参阅https://docs.puppet.com/puppet/latest/reference/modules_metadata.html#allowed-keys-in-metadatajson

与傀儡3.7.1类似的问题,为Fedora:无法findmy.server类puppet

解:

 sudo ln -s /my/local/copy/puppet/modules /etc/puppet/ 

然后它工作。

我有一个类似的问题。 在我的例子中,类名是“onehost :: change_IoT_password_reminder”。 使用strace之后,我发现puppet正在寻找一个modules / onehost / manifests / change_iot_password_reminder.pp文件。 似乎在类名中使用大写字母不是一个好主意,即使它不是该类的第一个字母。