如何从基于Ruby的自定义类型的清单中实例化定义的类型?

时间:2019-06-04 12:56:35

标签: puppet

我正在用Ruby编写自定义的Puppet资源类型,并希望使用其他模块中的类型。此其他类型在Puppet代码中定义。

从文档中,我可以这样做:

Puppet::Type.type(:file).new(file_opts)

这适用于使用ruby定义的类型,但不适用于使用{p> 1的.pp文件中定义的类型

define sysctl (){...}

这是基本的Ruby类型定义。我要覆盖generate,以便最终在自定义资源旁边添加其他资源。上面的type(:file)示例似乎是这样工作的:

Puppet::Type.newtype(:network_interface) do
  ensurable

  newparam(:name) do
    isnamevar
    desc 'The name of the physical network device'
  end

  def create
  end

  def generate
    [Puppet::Type.type('sysctl').new(
      name: "net.ipv4.conf.eth1.promote_secondaries",
      value: 1
    )]
  end
end

我收到此错误:

Network_interface[eth1]: Failed to generate additional resources using 'generate': undefined method `new' for nil:NilClass

我已经研究了Puppet代码,以尝试了解Puppet如何从define表单创建类型,但是没有运气。

0 个答案:

没有答案