【问题标题】:Puppet: Multiple manifests in modulePuppet:模块中的多个清单
【发布时间】:2014-09-06 09:15:32
【问题描述】:

我正在尝试创建Puppet 模块来设置我的网络服务器。

我想要的 - 是将配置拆分为逻辑模块(服务清单:webserver、database、ftp 等)但我不知道如何在 init.pp 中使用其他清单

我将仅将它与puppet apply 一起使用,而不是服务器-客户端配置。

我的文本模块清单 (kp/manifests/init.pp):

class kp {
    include kp::testfile
}

include kp

以及额外的清单 (kp/manifests/testfile.pp)

define kp::testfile {

    $value = template("kp/some.erb")

    file { 'testfile':
        path    => '/tmp/my.txt',
        ensure  => file,
        content => $value
    }
}

文档说:

If a class is defined in a module, you can declare that class by name in any manifest. Puppet will automatically find and load the manifest that contains the class definition.

但是当我运行 puppet apply init.pp 时,我收到了错误消息

Could not find class kp::testfile for myhost.com at /myDir/puppetModules/kp/manifests/init.pp:2 on node vagrant.example.com

事实

  • /myDir/puppetModules/ 在modulepath 所以这里没有问题
  • 傀儡版v2.7.11
  • Ubuntu 12.04 LTS

我做错了什么? 提前致谢!

【问题讨论】:

    标签: puppet


    【解决方案1】:

    您的 kp::testfile 是已定义的类型,而不是类。要使用已定义的类型,您需要将其声明为:

    kp::testfile { 'name': }
    

    尝试重新定义 kp::testfile 之类的

    class kp::testfile {
    
        $value = template("kp/some.erb")
    
        file { 'testfile':
            path    => '/tmp/my.txt',
            ensure  => file,
            content => $value
        }
    }
    

    你可能会有更好的运气。

    【讨论】:

    • 天哪,我花了这么多时间在它上面,它是如此简单。我现在不知道我从哪里得到那个带有“定义”的例子,但自从我写了它之后我就没有注意它。谢谢,看起来现在可以了!
    猜你喜欢
    • 2013-07-04
    • 1970-01-01
    • 1970-01-01
    • 2014-06-30
    • 1970-01-01
    • 1970-01-01
    • 2015-02-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多