Can Puppet install a command to be used later by a custom resource?

时间:2016-10-20 13:17:56

标签: puppet

I have a custom resource written in Ruby, whose provider uses a command. The command comes from an RPM package which I would also like Puppet to install. Even with what I believe are the right dependencies, this doesn't work, because the command method is evaluated while the catalogue is being compiled, before any resources have run. At least, that's my understanding.

Is there a way to make this work? In an agentless setup I could just run two separate manifests, but how will it work with Puppet Server?

1 个答案:

答案 0 :(得分:2)

提供使用commands指令(例如commands :foo => '/usr/bin/foo')应该在文件存在时自动开始用于资源,如果没有找到其他工作提供者。

commands在内部生成“confine”指令,将提供程序限制为仅在文件存在时运行。类似的是“特征”,例如要求加载某个Ruby库(“feature”)。当目录中没有其他工作提供者的资源存在时,Puppet代理应该为提供者不断重新评估所有这些。

使用--debug

运行时,您会在代理上看到此类消息
Debug: Puppet::Type::Example::ProviderExample: file /usr/bin/foo does not exist

文件出现后,邮件应该停止,并且应该运行使用提供程序的所有资源。如果文件未显示,则此消息将显示在代理程序运行结束时:

Error: Could not find a suitable provider for example

在考虑提供者之前,应始终在主服务器上编译目录,并且代理应该在失败这些资源之前尝试尽可能多地运行。

正如您所说,“如果你正确地做到这一点,这是有效的”!