简体   繁体   English

自定义木偶提供程序:如何从木偶主文件中检索文件

[英]Custom puppet provider: How to retrieve a file from puppet master

I need to retrieve a static file from within a custom Puppet provider from Puppet master (just like file built-in resource does). 我需要从Pu​​ppet master中的自定义Puppet提供程序中检索静态文件(就像文件内置资源一样)。 Defining a separate built-in file resource in Puppet code is not an option. 在Puppet代码中定义单独的内置文件资源不是一种选择。 So, in Puppet code the thing should look like this: 所以,在Puppet代码中,事物应该如下所示:

custom_type{
  property1 => 'value1'
  property2 => 'value2'
  file => "puppet:///${module_name}/somefile"
}

Although I've written custom types and providers before, interaction with Puppet master's file server is something I do not get. 虽然我以前写过自定义类型和提供程序,但是与Puppet master的文件服务器的交互是我无法获得的。

I suggest using the file type after all. 我建议毕竟使用file类型。 You need not do this from the manifest level. 您无需从清单级别执行此操作。 Puppet can handle this using generated resources . Puppet可以使用生成的资源来处理这个问题。

For example, the nagios types do something similar. 例如, nagios类型做类似的事情。

In your custom type code, introduce a generate hook. 在自定义类型代码中,引入一个generate钩子。

def generate
  if self[:file]
    Puppet::Type.type(:file).new({
      :name   => <whatever the path on the agent is>,
      :ensure => :present,
      :source => self[:file],
    })
  end
end

The agent takes care of adding this resource to the catalog. 代理负责将此资源添加到目录。

Looking into the puppet file type , it looks like this is what you want on line 103: 查看puppet文件类型 ,看起来这就是你想要的第103行:

 Puppet::FileServing::Content.indirection.find(metadata.source, :environment => resource.catalog.environment_instance, :links => resource[:links]) 

metadata.source is the path to the file. metadata.source是文件的路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM